我的 ASMX 代理方法中的这些额外参数是什么?
如果我将来自 .NET 1.1 客户端的 Web 引用添加到 WCF 服务,则客户端生成的代理方法将包含一个以每个服务方法参数的后缀“指定”结尾的额外参数,例如,
[OperationContract]
string HelloWorld(string foo, int bar);
结果为:
Service1.HelloWorld(string foo, bool fooSpecified, int bar, bool barSpecified);
我的服务参数是' t 是可选的,那么客户端的这些额外参数是什么,我怎样才能摆脱它们呢?
If I add a web reference from a .NET 1.1 client to a WCF service, the proxy methods generated at the client contain an extra parameter ending with the suffix 'Specified' for each service method parameter, e.g.
[OperationContract]
string HelloWorld(string foo, int bar);
results in:
Service1.HelloWorld(string foo, bool fooSpecified, int bar, bool barSpecified);
My service parameters aren't optional so what are these extra parameters at the client, and how can I get rid of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是由于 WCF 和 ASMX Web 服务中使用的序列化机制存在差异造成的。
为了避免额外的参数,您必须在 ServiceContract 上指定 XmlSerializerFormat 属性。
要添加,请阅读以下内容:
http:// /msmvps.com/blogs/windsor/archive/2008/05/17/calling-wcf-services-from-net-1-1.aspx
This is due to a difference in the serialization mechanisms used in WCF and ASMX Web Services.
To avoid extra params you must specify XmlSerializerFormat attribute on ServiceContract.
for add read this:
http://msmvps.com/blogs/windsor/archive/2008/05/17/calling-wcf-services-from-net-1-1.aspx
问题在于允许不存在值类型的参数。如果没有
*specified
参数,.NET 1.1 无法指定这一点。它们需要设置为 true 以指示正在发送相应的参数。The issue is with parameters of a value type when they are permitted to be absent. .NET 1.1 has no way to specify this without the
*specified
parameters. They need to be set to true to indicate that the corresponding parameter is being sent..NET 1.1 Web 服务没有 null 的概念,因此 WCF 会为您生成这些额外的属性。 fooSpecified = false 表示 foo 实际上为 null。
.NET 1.1 Web services don't have a concept of null so WCF is generating these extra properties for you. fooSpecified = false means foo is really null.
您可能需要说明您的参数是必需的
You probably need t osay that your parameters are required