Friday, August 8, 2008

WSDL - Web Services Description Language


WSDL - Web Services Description Language


You may like to refresh your understanding of the Web Services by going through this article - Web Services - What, Why, Usage, & Shortcomings>>


The WSDL (Web Services Description Language) is a grammar which uses XML for describing all the details of a Web Service which a consumer may like to have for using that Web Service. These details are:-
  • Message Exchanges - this is used to define the input and out message exchanges between the Web Service and the Consumer. Why to use a new language for it? Can't we use XML Schema to define such message exchanges? No... the XML Schema is not capable of describing it. Take one example to understand it - suppose you have two XML elements RequestMessage and ResponseMessage and if you want to specify that if the Consumer sends the RequestMessage then it will get the ResponseMessage. Now in this case XML Schema can't be used as it's not capable of describing the relation between the XML Elements. WSDL uses the concept of 'operations' to describe such a situation.
  • Grouping of similar operations into interfaces - WSDL helps grouping similar operations into interfaces which can be mapped to the programmatic interfaces in object-oriented languages.
  • Binding Specification - binding is actually a combination of an interface and the communication protocol and it's used to specify the concrete details of what actually travels on the wire. In addition to the interfaces and communication protocol, the binding is influenced by the Style of the Service (which can either be 'document' or 'RPC') and by the Encoding Mechanism (which can either be 'literal' or 'encoded'). For one interface we may have multiple binding for the simple reason that a binding is a combination of the interface and the communication protocol. So for the same interface we may have different bindings for TCP, HTTP, SMTP, etc. communication protocols. For every binding there will be a distinct URI each of which can be used to consume the Web Service.


In a nutshell we can say that WSDL uplifts the capabilities of XML Schema by providing a way of describing the message exchanges in form of operations and by providing a way of grouping similar operations into interfaces. It also facilitates the specification of the particular communication protocol, style, and encoding mechanism used by the Web Service. Every combination of the interface and communication protocol is represented by a binding and every binding will have a distinct URI. That means the same service may be consumed by using different communication protocols by simply using the corresponding URIs.


There are other techniques for describing the Web Services, but WS-I Basic Profile v1.0 makes it mandatory to use the WSDL and XML Schema for describing any Web Service. This ensures the interoprability at the service description layer.


A WSDL document is simply an XML document and hence it's quite easier for the developer to read, interpret and generated the code to consume the Web Service. We have many tools available by reputed vendors which can be directly used to consume any Web Service.


WSDL 1.1 is was being used as a de-facto standard until mid of the year 2007 when W3C came up with WSDL 1.2 which is more commonly known as WSDL 2.0 and the tools and infrastructure developers have already started following this version. The entire WSDL Schema can be found here - WSDL Schema.



WSDL Elements


Find below the elements of a typical WSDL document:-


  • types - this element is used to define an abstract type which will be used by the XML Schema.
  • message - this element is used to define an abstract message and it may consist of multiple parts where each part may be of different type - either a built-in type or an abstract type defined by the 'types' element.
  • portType - this element is used to define the interface by grouping similar operations together. As discussed above, one interface may be combined with multiple communication protocols to form different end-points (URIs) of the same service.
  • binding - this element is used to specify the details of the communication protocol, style of service, and encoding mechanism for the particular URI (end-point) of a particulat portType element. One binding element is used to completely describe one URI for a particular portType element and hence one portType element may have multiple binding elements to have as many different end-points.
  • service - this element is used to represent a collection of ports. A port is given a name and a binding is assigned to it which this port will expose. Now every port is given an URL which is used to access the service. Now if we have more than one binding element for the same portType element then we can simply have as many port elements in the serive element and assign all these port elements a distinct URL. The associated binding element for any URL will determine which communication protocol to consume the service will be used in that case.

Now that you know what all elements a WSDL doc may have and what these elements actually mean, check this Sample WSDL Document and try to identify and co-relate all the elements of it.


References



Share/Save/Bookmark


No comments: