为什么在我的WCF Web服务参考额外的参数?

问题描述:

我想一个ASP.Net Web服务转换为WCF应用程序。客户端是在.NET Compact Framework中不支持WCF,所以我需要确保WCF保持支持ASP风格的Web服务。当我添加在Visual Studio中的Web服务引用生成的代理类的方法有额外的参数。

I'm trying to convert an ASP.Net web service to WCF application. The client is on the .Net Compact Framework which does not support WCF so I need to make sure the WCF keeps supporting ASP style webservices. When I add the web service reference in Visual Studio the generated proxy class' methods have extra arguments.

例如,如果一个方法被定义为:

For example if a method is defined as:

public void GetEmpInfo(int empNo)

这方法会出现在代理类为:

That method will appear in the proxy class as:

public void GetEmpInfo(int empNo, bool empNoSpecified)

是什么原因造成这一点,我怎么得到它停​​止?

What causes this, and how do I get it to stop?

看看这个博客文章 ...

在哪里这些额外的布尔
规定成员来自什么
他们这样做?答案是模式
的WCF数据契约串行
默认生成。因为
方式的版本模型的工作原理,在
串行器产生的所有数据成员
作为可选元素。较老的网
服务栈,ASP.NET Web服务
(ASMX),使用不同的序列化,
XmlSerializer的,它保持
全架构和XML保真度。的
XmlSerializer的所有可选
元素映射到两个构件:一种
表示数据本身,和一个
指定数据是否是
实际存在 - 这是在
xxxSpecified的成员。这些
xxxSpecified成员必须设置为
真使$ B $的序列B中的相应的实际数据
的成员。

Where did these extra boolean "specified" members come from and what do they do? The answer is the schema that the WCF data contract serializer generates by default. Because of the way its versioning model works, the serializer generates all data members as optional elements. The older web services stack, ASP.NET Web Services ("ASMX"), uses a different serializer, the XmlSerializer, which maintains full schema and XML fidelity. The XmlSerializer maps all optional elements to two members: one represents the data itself, and one specifies whether or not the data is actually present – this is the "xxxSpecified" member. These xxxSpecified members must be set to true to enable the serialization of the corresponding "actual data" members.