Mykroft
Mykroft

Reputation: 13435

Why are there extra arguments in my wcf web service reference?

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?

Upvotes: 6

Views: 4044

Answers (3)

Ash
Ash

Reputation: 6035

This happens for types with a default value of not null. In these cases, it's impossible for the web service to know whether a parameter was set to the default value or simply not set at all.

You can get rid of the extra specification parameter by decorating your operation with the [XmlSerializerFormat] attribute like:

    [OperationContract]
    [XmlSerializerFormat]
    string GetEmpInfo(int? empNo);

This attribute can also be added at the Class level, and this would make sense in most cases.

I understand you can handle this situation using nullable types (int?), but I was unable to fix it using this.

Upvotes: 1

Scott Ewers
Scott Ewers

Reputation: 664

The .NET Compact Framework does support a subset of WCF. You can review this support on MSDN. Take a look, it may support enough for you to remove your legacy Web Services support.

Upvotes: 1

JP Alioto
JP Alioto

Reputation: 45117

Check out this blog post ...

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.

Upvotes: 8

Related Questions