Allan

Allan

  • NA
  • 4
  • 0

Service xml serialization [XmlAttributeAttribute()] ignored

Dec 20 2012 9:42 AM
Hi,

I have a WCF web service developed with VS2010 targeting .Net Framework 4 which utilizes a serialization class generated from a xsd schema using xsd.exe.

When I request the xsd from the service (http://localhost:59120/Service1.svc?xsd=xsd2) the element attributes are ignored. E.G. in the schema snippet below (<xs:element name="id"...>) should be an attribute (<xs:attribute name="id"...>).

XSD schema snippet
...
<xs:sequence>
<xs:element name="address" type="xs:string" nillable="true"/>
<xs:element name="emailId" type="xs:string" nillable="true"/>
<xs:element name="id" type="xs:string" nillable="true"/>
<xs:element name="items" type="tns:ArrayOfArrayOfOrdersCustomerItemsItem" nillable="true"/>
<xs:element name="name" type="xs:string" nillable="true"/>
</xs:sequence>
...

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.296
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

//
// This source code was auto-generated by xsd, Version=4.0.30319.1.
//
namespace WcfService1
{
    using System.Xml.Serialization;


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [XmlTypeAttribute(AnonymousType = true)]
    [XmlRootAttribute(Namespace = "", IsNullable = false)]
    public partial class Orders
    {

        /// <remarks/>
        [XmlElementAttribute("Customer", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
        public OrdersCustomer[] Items;
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [XmlTypeAttribute(AnonymousType = true)]
    public partial class OrdersCustomer
    {

        /// <remarks/>
        [XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
        public string Name;

        /// <remarks/>
        [XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 1)]
        public string Address;

        /// <remarks/>
        [XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 2)]
        public string EmailId;

        /// <remarks/>
        [XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 3)]
        [XmlArrayItemAttribute("Item", typeof(OrdersCustomerItemsItem), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
        public OrdersCustomerItemsItem[][] Items;

        /// <remarks/>
        [XmlAttributeAttribute()]
        public string Id;

    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [XmlTypeAttribute(AnonymousType = true)]
    public partial class OrdersCustomerItemsItem
    {

        /// <remarks/>
        [XmlAttributeAttribute()]
        public string Id;

        /// <remarks/>
        [XmlAttributeAttribute()]
        public string Name;
    }
}