tags:

views:

304

answers:

1

We have a wsdl specifying a datetime element. It is nullable, in the sense that minOccurs=0. However, using svcutil to generate a proxy class does not give us a .net nullable DateTime property, so how best can we make the proxy class serialise the message to a SOAP message that does not contain the datetime element?

+1  A: 

svcutil handles the case where an element is marked as minOccurs="0" by generating an extra Boolean property called "xxxSpecified" (where "xxx" is the element name). To exclude the element from your SOAP message, you must set that property to false. To include the element, you must set that property to true.

So if the element were called "Fred", svcutil would give you two properties in your proxy class:

DateTime Fred

and

bool FredSpecified

If you want to include Fred in the SOAP message, you should set the Fred property to the datetime you want to send, and set FredSpecified to true.

If you do not want to include Fred in the SOAP message, you should set FredSpecified to false (and it doesn't matter what value is in the Fred property).

svcutil will only give you proper nullable types if your WSDL uses the nillable="true" style of nulls, rather than the minOccurs="0" style.

Eric Rosenberger