-
Dec 20th, 2012, 07:29 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] VS2010: Service xml serialization [XmlAttributeAttribute()] is ignored
Hi,
I have a WCF web service 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 being ignored. E.G. in the schema snippet below (<xs:element name="id"...>) should be an attribute (<xs:attribute name="id"...>).
XML
Code:
...
<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>
...
C# Serialization class -
C#
Code:
//------------------------------------------------------------------------------
// <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;
}
}
-
Dec 21st, 2012, 06:14 AM
#2
Thread Starter
Fanatic Member
Re: VS2010: Service xml serialization [XmlAttributeAttribute()] is ignored
Hi,
I believe that I've fixed this by changing the default serializer. From .Net Framwork 3.0 microsoft changed the default serializer to the DataContract serializer, which is different from the XmlSerializer that ASMX uses.
"Therefore, the XSD generated varies, too - the DataCOntract serializer for example doesn't support XML attributes (for speed reasons)."
I specified the XmlSerializer in the service interface [Contract] last night and it seems to be producing the expected xsd now. I did this late last night so haven't tested it properly yet and I'm off now until the new year.
Here are some links to the thread where I found the info I've been looking for -
http://stackoverflow.com/questions/2592664/schema-generated-from-wcf-web-service-and-asmx-are-different?rq=1
Blog post comparing the two serializers
Serialization in WCF
Last edited by aconybeare; Jan 2nd, 2013 at 10:38 AM.
Reason: Fixed typo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|