WCF Service parameters changed in .NET 2.0 client

wcf

I created a WCF service that exposed a method that has one paramater:

public class Service1 : IService1
{
    public string GetData(int value)
    {
        return string.Format("You entered: {0}", value);
    }
}

The service has two endpoints defined (wsHttpBinding and basicHttpBinding) so that it would be compatable with older clients.

The service runs just fine in a .NET 3.0 and .NET 3.5 client app. However, when I create a .NET 2.0 client, the GetData method requires 2 parameters: an integer (expected) and a bool parameter called valueSpecified (unexpected). I never defined the second parameter. Why is this happening and how can I get rid of the second parameter?

Best Answer

Since value types can't be null (in latter versions of .net framework there is no Nullable<T>) VS besides to generate additional parameter to give you ability to not specify value type, you can call your service method like this.

service.GetData(val,true);

see this post, where John Saunders suggest to add [DataMember(Required = true)] attribute in the property.