What is WSDL: WSDL Tutorial

Many new webservice developers face this question – What is WSdL. This WSDL tutorial explains: WSDL, webservice description language, is the contract definition of any webservice. This XML document is used to tell the world what is going to be the definition/structure of the webservice, what that webservice has to offer. Here is an example webservice document explained using inline comments. We are not taking any complex example here. But it is very close to real life wsdl. There are many tools available that can be used to write wsdl.

What is WSDL? WSDL Tutorial

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://www.deepakgaikwad.net/ws/ExampleServices"

<!-- Document the wsdl -->
		This is an example service.

<!-- types are the input and output parameters  you are going 
to use in the operations. Ensure usage of generic types that can 
be recongnised in all technologies implementing web service -->
    <xs:schema targetNamespace="http://www.deepakgaikwad.net/sample.xsd"
      <xs:element name="sampleRequest">
            <xs:element name="param1" type="string"/>
      <xs:element name="sampleResponse">
             <xs:element name="result1" type="float"/>

<!-- These are the data elements of operations of webservice. 
We use the types defined above to define define the messages. 
These map to the input/output parameters of the underlying webservice implementation.-->

  <wsdl:message name="sampleRequest">
    <wsdl:part name="SampleRequest" element="sampleRequest" />
  <wsdl:message name="sampleResponse">
    <wsdl:part name="SampleResponse" element="sampleResponse" />

<!-- Operations exposed by web service. These map to the methods/operations 
of webservice. Type of operations are - one way (containing only input), 
request-response (both input and output), solicit response (does wait 
for response), notification (does not wait for response)-->

  <wsdl:portType name="SampleWS">
    <wsdl:operation name="sampleOperation">
				Sample operation
      <wsdl:input message="sampleRequest" />
      <wsdl:output message="sampleResponse" />

  <!-- Defines message format and protocol details of webservice. 
  Here the transport is http.
  Also it defines the url to be used to access.-->

  <wsdl:binding name="SampleWS" type="SampleWS">
    <soap:binding style="document"
      transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="sampleOperation">
        soapAction="http://${hostname}:${port}/ExampleServices/ws/sampleOperation" />
        <soap:body use="literal" />
        <soap:body use="literal" />

How to Write a WSDL?
It is up to us whether we handwrite a wsdl or generate it using some tool. XMLSpy, Rational Application Developer and other tools are available that make our life easy. But if we are using Java 5, then you can use annotations in your input parameter classes, which will allow us to generate the wsdl using some command. Application servers also provide libraries to generate the wsdl, when you generate service.

Be the first to comment

Leave a Reply

Your email address will not be published.