asmx .NET Web Service Nuances
When the WSDL specifies that the minimum occurrence of certain elements is zero, the .NET WSDL proxy generator will generate 2 properties for that element (instead of 1).
On top of what usually gets generated – a property named according to the XML element – the generator creates another property namedSpecified of Boolean type.
As an example: the WSDL specifies an XML element named policy of type string with minimum occurrence of zero.
On top of what usually gets generated – a property named according to the XML element – the generator creates another property named
As an example: the WSDL specifies an XML element named policy of type string with minimum occurrence of zero.
<xs:element minOccurs=”0” name=”policy” type=”xs:string” />The generated proxy code will have a read/ write property named policy as expected
public string policy {Due to the minimum occurrence constraint, another read/ write property named policySpecified will be generated.
get { return _policy; }
set { _policy = value; }
}
public bool policySpecified {The use of this property is to indicate to the framework that the particular property is in use (or has been specified). This will result in the framework generating the XML element in the SOAP message.
get { return _policySpecified; }
set { _policySpecified = value; }
}
// the correct method of setting optional elementsOtherwise, the XML element will not be automatically generated in the SOAP message even though the property appears to have been set.
soapInput.policy = “XXXX”;
soapInput.policySpecified = true;
// will not result in the XML element appearing in the SOAP message
soapInput.policy = “XXXX”;
Comments