What are these extra parameters in my ASMX Proxy M

2019-01-26 09:35发布

问题:

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?

回答1:

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



回答2:

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.



回答3:

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



回答4:

You probably need t osay that your parameters are required

[OperationContract] 
string HelloWorld([RequiredDataParameter] string foo,
                  [RequiredDataParameter] int bar);


标签: c# .net wcf asmx