Reputation: 563
I am curious about the way a non-.NET client application of a WCF service can signal to a given method that it doesn't want to specify a value for a given parameter (making the service then assuming a default value). In other words, how can an application signal a null
parameter to a WCF service?
Upvotes: 4
Views: 5575
Reputation: 43698
In addition to Ethan's answer, you can also set the IsRequired property on the DataMember attribute:
[DataMember(IsRequired=false)]
When set to false, the DataContractSerializer will set the property to its default value (null, for any nullable types) when that property is missing in the SOAP message. Sometimes it may be easier for SOAP clients in otehr languages to just omit the property, rather than send <myProperty xsi:nil="true"/>
Upvotes: 3
Reputation: 32936
It can exclude the parameter from the SOAP document (assuming HTTP endpoint), assuming this is allowed.
Exactly if this is allowed/how this should be done depends on how the XSD is generated.
These can be controlled by the arguments to the [DataMember]
attribute.
If [DataMember(IsRequired=true)]
MSDN then the xml will be required to contain this element (minOccurs will be 1 I believe), and if the element may be nillable (nillable=true, depending on datatype)
If [DataMember(EmitDefaultValue=true)]
MSDN then there will be an element if the element has its default value when the item is serialized.
Upvotes: 3
Reputation: 4993
If you are communicating to the service using SOAP (or some other XML based standard) you can supply the propery using: <myProperty xsi:nil="true"/>
. How the non-.NET client application generates a nil
value is going to be specific to the framework you are using.
Upvotes: 3