Removing an optional value type element from a SOAP message sent through a WCF proxy

We have a wsdl defining a datetime element. It is NULL in the sense that minOccurs = 0. However, using svcutil to create a proxy class does not give us a nullTime property with a .net value, so what is the best way to make the proxy series serialize the message to a SOAP message that is not contains a datetime element?

+1


source to share


1 answer


svcutil handles the case where an item is marked with minOccurs = "0" by creating an additional boolean property called "xxxSpecified" (where "xxx" is the name of the item). To exclude an element from your SOAP message, you must set this property to false. To enable an element, you must set this property to true.

So, if this element was called "Fred", svcutil will provide you with two properties in your proxy class:

DateTime Fred

and



bool FredSpecified

If you want to include Fred in a SOAP message, you must set the Fred property to the date and time you want to send and set FredSpecified to true.

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

svcutil will only give you null types if your WSDL uses nillable = "true" and not the minOccurs = "0" style.

+2


source







All Articles