So in xml this element can have a value:
Or be omitted at all:
This is a challenge to many web services frameworks since when generating proxy code an element is usually mapped to one language variable. A variable in a programming language does not natively support metadata such as being "nullable" or "optional".
In some frameworks the solution is to add a "controller" field. For example some Java frameworks would create something like this:
In .Net 2.0 part of this informaiton is in a controller field and part in .Net attributes. For example a nillable string is:
And an optional int is:
What happens in .Net when an element is both nullable and optional?
There is no problem with an int - we can use System.Nullable:
So now "i" can both have a value of null and seperately be specified as ommited.
String is more challenging since it can have null from the first place so "string?" is meaningless. We would expect to have:
However for some reason .Net does not generate this for the client side so it does not support out of the box a string which if both optional and nullable.
The solution is to manually add the sSpecified element and the XmlIgnore attribute as above to the client proxy or the server side code.
Note: For the client proxy updating the service reference will override any such change so use this method only if you have no other choice. For example use it when you try to interoperate with a framework that requires this.