1
votes

I have the following class

[Serializable()]  
[XmlType(AnonymousType=true)][XmlRoot(Namespace="", IsNullable=false)]  
public class Test  
{  
   [XmlAttribute()]  
   public string Prop { get; set; }  

   public string Another { get; set; }  
}

I used this class in both a WCF web service (SVC) and an ASMX web service and I'm expecting to get a SOAP body which are consistent for both ASMX and SVC where the "Prop" property is an attribute. Also, I tried adding a service and web reference to both SVC and ASMX and here's how the XSDs looked like:

  1. Service Reference to SVC: Did not create XmlAttribute attribute for Test.Prop property
  2. Service Reference to ASMX: Created XmlAttribute attribute for Test.Prop property
  3. Web Reference to SVC: Created XmlElement for Test.Prop property
  4. Web Reference to ASMX: Created XmlAttribute attribute for Test.Prop property

My question is why are the generated XSDs and therefore SOAP XMLs not consisted? I know this does not matter as both methods worked regardless of the generated schema.

1

1 Answers

2
votes

WCF uses the DataContract serializer by default, which is different from the XmlSerializer that ASMX uses. Therefore, the XSD generated will vary, too - the DataCOntract serializer e.g. doesn't support XML attributes (for speed reasons).

Check out Dan Rigsby's excellent blog post comparing the two serializers, and Aaron Skonnard's MSDN Magazine article Serialization in WCF for more details.