开发者

Schema generated from WCF web service and ASMX are different

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜