If you had a desktop client that worked with the desktop’s AddServiceReference, and now wanted to use the same code on a mobile client – generating the proxy with a NetcfSvcUtil.exe tool, there is a gotcha that I recently got a customer query about. If you tried to send out an object which had value types like int and double as data members, the server might behave as if the values were not sent. The reason is because of the differences in the proxy stub data contract generated by the NetcfSvcUtil.exe.

Lets say, the original datacontract of the class on the server specifies:

public class MyCustomData
    {
        int intValue = 10;

        [DataMember]
        public int IntValue
        {
            get { return intValue; }
            set { intValue = value; }
        }
    }

The NetcfSvcUtil.exe though generates a class of the following format:

public class MyCustomData {

[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public int IntValue
{
    get
    {
        return this.intValueField;
    }
    set
    {
        this.intValueField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IntValueSpecified
{
    get
    {
        return this.intValueFieldSpecified;
    }
    set
    {
        this.intValueFieldSpecified = value;
    }
} }

Now, notice the fact that both IntValue and IntValueSpecified are defined on the client side, and both need to be specified for the proxy to generate the xml necessary for the IntValue data in the request to be sent to the server.

So, unlike a desktop client, that just writes to the IntValue property, to achieve the right results, you need to do the following:

MyCustomData data = new MyCustomData();

data.IntValue = 100;

data.IntValueSpecified = true;

And now call into the proxy methods.