Guideline: java.awt.Image, javax.xml.transform.Source, and javax.activation.DataHandler map to xs:base64Binary. .NET maps xs:base64Binary to byte[].
JAXB 2.0 provides the annotation @XmlMimeType, which supports specifying the content type, but .NET ignores this information.
Example: Mapping java.awt.Image without @XmlMimeType
//-- Java code fragment
public class Claim {
public java.awt.Image photo;
}
//-- Schema fragment
<xs:complexType name="claim">
<xs:sequence>
<xs:element name="photo" type="xs:base64Binary" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
//-- .NET auto generated code from schema
public partial class claim : object,
System.Runtime.Serialization.IExtensibleDataObject
{
private byte[] photoField;
//-- ..... other generated code .......
public byte[] photo
{
get { return this.photoField; }
set { this.photoField = value; }
}
}
//-- C# code fragment
try
{
claim tmpC = new claim();
System.IO.FileStream f = new System.IO.FileStream(
"C:\\icons\\circleIcon.gif", System.IO.FileMode.Open);
int cnt = (int)f.Length;
tmpC.photo = new byte[cnt];
int rCnt = f.Read(tmpC.photo, 0, cnt);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Example: Mapping java.awt.Image with @XmlMimeType
//-- Java code fragment
public class Claim {
@XmlMimeType("image/gif")
public java.awt.Image photo;
}
//-- Schema fragment
<xs:complexType name="claim">
<xs:sequence>
<xs:element name="photo" ns1:expectedContentTypes="image/gif"
type="xs:base64Binary" minOccurs="0"
xmlns:ns1="http://www.w3.org/2005/05/xmlmime"/>
</xs:sequence>
</xs:complexType>
//-- Using the @XmlMimeType annotation doesn’t change .NET
//--auto generated code
public partial class claim : object,
System.Runtime.Serialization.IExtensibleDataObject
{
private byte[] photoField;
//-- ..... other generated code .......
public byte[] photo
{
get { return this.photoField; }
set { this.photoField = value; }
}
}
//-- This code is unchanged by the different schema
//-- C# code fragment
try
{
claim tmpC = new claim();
System.IO.FileStream f = new System.IO.FileStream(
"C:\\icons\\circleIcon.gif", System.IO.FileMode.Open);
int cnt = (int)f.Length;
tmpC.photo = new byte[cnt];
int rCnt = f.Read(tmpC.photo, 0, cnt);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}