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:
- Service Reference to SVC: Did not create XmlAttribute attribute for Test.Prop property
- Service Reference to ASMX: Created XmlAttribute attribute for Test.Prop property
- Web Reference to SVC: Created XmlElement for Test.Prop property
- 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.
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.
精彩评论