在WCF代理生成的客户端中,什么决定使用的序列化程序? [英] In a WCF proxy-generated client, what determines the serializer used?

查看:101
本文介绍了在WCF代理生成的客户端中,什么决定使用的序列化程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用DataContact/DataMember属性公开WCF服务时,我在其他项目中对此服务所做的每个服务引用都会生成具有DataContract/DataMember属性的类(以及IExtensibleDataObject接口实现等).

When I expose a WCF service using DataContact/DataMember attributes, each service reference I make in other projects to this service generates classes with DataContract/DataMember attributes (as well as IExtensibleDataObject interface implementation, etc.).

在另一个项目中,我必须使用SOAP服务,该服务的WSDL不是由WCF生成的,而是由我不知道并且无法更改其行为的其他工具来实现.

In another project, I have to use a SOAP service whose WSDL has not been generated by WCF, but by some other tool I don't know and can't change the behavior.

我的问题是我的svcutil代理生成的代码不太灵活:

My problem is that the code generated by my svcutil proxy is a little bit less flexible:

  • 这些类使用Serializable属性而不是DataContract(GeneratedCode属性指定使用System.Xml代替System.Runtime.Serialization)
  • 未实现IExtensibleDataObject
  • 未使用OptionalField属性
  • XmlElement的顺序是固定的,当在wsdl xs:sequence的中间插入新的xs:element时,导致反序列化失败.

在svcutil工具/我使用的wsdl中发生了什么事,它必须以这种方式生成代码?

What happened in the svcutil tool / the wsdl I use, that it has to generate code in this way?

推荐答案

在svcutil工具/我使用的wsdl中发生了什么,它必须 以这种方式生成代码?

What happened in the svcutil tool / the wsdl I use, that it has to generate code in this way?

Svcutil.exe工具可用于为WCF和ASMX服务创建客户端代理.使用Svcutil.exe从ASMX服务创建代理时,代码中生成的数据类型通常使用XML序列化.

The Svcutil.exe tool can be used to create client proxies for both WCF and ASMX services. When Svcutil.exe is used create a proxy from an ASMX service, the data types that are generated in the code usually use XML serialization.

http://msdn.microsoft.com/en-us/library/cc304837.aspx

更新:

我的最佳猜测是WSDL中指定的架构确定svcutil.exe必须使用哪种序列化.

My best guess is it is the schema specified in the WSDL determines which serialization has to be used by the the svcutil.exe.

数据协定序列化架构的名称空间为 http://schemas.microsoft.com/2003/10/序列化,您可以在此处.

The namespace of data contract serialization schema is http://schemas.microsoft.com/2003/10/Serialization and you can get much details about that here.

因此,如果svcutil看到了在wsdl中指定的此架构,则它将用于数据合同串行化器,否则将用于xml序列化器.

So if the svcutil sees this schema specified in the wsdl then it go for data-contract serializer else the xml serializer.

我还检查了WCF和ASMX的WSDL. WCF服务的WSDL包含以下XSD部分,而ASMX的XSD部分中没有这些部分.

I also checked with WSDLs of WCF and ASMX. The WSDL of WCF service contains the following XSD sections and they are missing in the ASMX's one.

<xsd:schema targetNamespace="http://tempuri.org/Imports">

   <xsd:import schemaLocation="http://localhost:53328/Service1.svc?xsd=xsd0"
     namespace="http://tempuri.org/"/>

   <xsd:import schemaLocation="http://localhost:53328/Service1.svc?xsd=xsd1" 
     namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>

   <xsd:import schemaLocation="http://localhost:53328/Service1.svc?xsd=xsd2" 
      namespace="http://schemas.datacontract.org/2004/07/WcfService1"/>
</xsd:schema>

这篇关于在WCF代理生成的客户端中,什么决定使用的序列化程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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