WCF web service和ASMX生成的Schema不一样 [英] Schema generated from WCF web service and ASMX are different

查看:40
本文介绍了WCF web service和ASMX生成的Schema不一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程

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

   public string Another { get; set; }  
}

我在 WCF Web 服务 (SVC) 和 ASMX Web 服务中都使用了这个类,我希望获得一个 SOAP 主体,该主体对于 ASMX 和 SVC 都是一致的,其中Prop"属性是一个属性.此外,我尝试添加对 SVC 和 ASMX 的服务和 Web 引用,XSD 如下所示:

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. 对 SVC 的服务引用:未为 Test.Prop 属性创建 XmlAttribute 属性
  2. 对 ASMX 的服务引用:为 Test.Prop 属性创建 XmlAttribute 属性
  3. 对 SVC 的 Web 参考:为 Test.Prop 属性创建了 XmlElement
  4. 对 ASMX 的 Web 参考:为 Test.Prop 属性创建了 XmlAttribute 属性

我的问题是为什么生成的 XSD 和 SOAP XML 不包括在内?我知道这并不重要,因为无论生成的架构如何,这两种方法都有效.

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 默认使用 DataContract 序列化器,这与 ASMX 使用的 XmlSerializer 不同.因此,生成的 XSD 也会有所不同 - DataCOntract 序列化程序,例如不支持 XML 属性(出于速度原因).

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).

查看 Dan Rigsby 的优秀比较两个序列化程序的博客文章,以及 Aaron Skonnard 的 MSDN 杂志文章 WCF 中的序列化 了解更多详情.

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.

这篇关于WCF web service和ASMX生成的Schema不一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆