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"
  xmlns="http://www.deepakgaikwad.net/ws/ExampleServices"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

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

<!-- 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 -->
  <wsdl:types>
    <xs:schema targetNamespace="http://www.deepakgaikwad.net/sample.xsd"
            xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="sampleRequest">
        <xs:complexType>
          <xs:all>
            <xs:element name="param1" type="string"/>
          </xs:all>
        </xs:complexType>
      </xs:element>
      <xs:element name="sampleResponse">
         <xs:complexType>
           <xs:all>
             <xs:element name="result1" type="float"/>
           </xs:all>
         </xs:complexType>
      </xs:element>
    </xs:schema>
  </wsdl:types>

<!-- 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>
  <wsdl:message name="sampleResponse">
    <wsdl:part name="SampleResponse" element="sampleResponse" />
  </wsdl:message>

<!-- 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">
      <wsdl:documentation>
				Sample operation
      </wsdl:documentation>
      <wsdl:input message="sampleRequest" />
      <wsdl:output message="sampleResponse" />
    </wsdl:operation>
  </wsdl:portType>

  <!-- 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">
      <soap:operation
        soapAction="http://${hostname}:${port}/ExampleServices/ws/sampleOperation" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

</wsdl:definitions>
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.


*