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 named Specified of Boolean type.

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 {

   get { return _policy; }
   set { _policy = value; }
}
Due to the minimum occurrence constraint, another read/ write property named policySpecified will be generated.
public bool policySpecified {
   get { return _policySpecified; }
   set { _policySpecified = value; }
}
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.
// the correct method of setting optional elements

soapInput.policy = “XXXX”;
soapInput.policySpecified = true;
Otherwise, the XML element will not be automatically generated in the SOAP message even though the property appears to have been set.
// will not result in the XML element appearing in the SOAP message

soapInput.policy = “XXXX”;

Comments

Popular posts from this blog

Understanding ITIL Service Management the UML way…

How to depict (Professional-Looking) Logical Network Diagrams in Astah