The WSIT Tutorial

@XmlType Annotation - Anonymous Type

Guideline: Prefer mapping class to named XML schema type rather than an anonymous type for a better .NET type binding.

The @XmlType annotation is used to customize the mapping of a Java class to an anonymous type. .NET binds an anonymous type to a .NET class - one per reference to the anonymous type. Thus, each Java class mapped to an anonymous type can generate multiple classes on the .NET client.

Example: Mapping a Java class to an anonymous type using @XmlType

//-- Java code fragment
public class PurchaseOrder {
    public java.util.List<Item> item;
public class Item {
    public String productName;

//-- Schema fragment
<xs:complexType name="purchaseOrder">
        <xs:element name="item">
                    <xs:element name="productName" type="xs:string"/>
>        </xs:element>

// C# code generated by svcutil
public partial class purchaseOrder
    private purchaseOrderItem[] itemField;
        Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true, Order=0)]
    public purchaseOrderItem[] item
        get {
            return this.itemField;

        set {
            this.itemField = value;

// .NET auto generated code from schema
public partial class purchaseOrderItem
    private string productNameField;
    public string productName {
        get { return this.productNameField; }
        set { this.productNameField = value; }