SOAP WSDL binding type

I recently came across a stumbling block while writing a WSDL for a Web Service. Many of the WSDL validators I tried were raising a validation error while parsing the WSDL.

Well, I learnt something new. The issue was that the WSDL had attributes defined for the XML. i.e. the XML resulting from the WSDL was making use of attributes.

The SOAP binding in the WSDL gives us a way to specify how the web service is bound to a messaging protocol, in particular the SOAP protocol for this case. This binding can be utilized in two ways: encoded or literal.

Here’s the catch. In case you use a binding of encoded, then its not possible to use attributes in your XML. Thats because each element of your XML would then have an attribute defined automatically (type), which tells you about the type of the element. For example: <x type=”xsd:int”>5</x> It would not be considered safe to put your own attributes for the x element, for the simple reason being, what if element x has an attribute named “type” defined in your WSDL? Thus most WSDL validators will either flag the WSDL as invalid or just plain refuse to include attributes in your XML.

The way to get around this in case you’re adamant on using attributes for your XML, is to use a SOAP binding of “literal”. Doing this, does not include the element type information in the XML, and you can then use attributes for your elments. Example XML: <x width=”6″>5</x>

This article provides a nice comparion about the different WSDL styles one can use.