Tuesday, 20 November 2012

WSDL(Web Services Description Language)

WSDL is an agreement between the service provider and consumer. It states how the service can be accessed and what the service offers, what are the inputs, what are the outputs, and what will be returned.To be more specific WSDL specifies the

Types:The data types used by the web service
Message: The messages used by the web service
Port-type: The operations that can be performed, and the messages that are involved
Binding: The communication protocols used by the web service
Lets see each of them in detail... starting with Types first...

 Types: The <types> element defines the data types that are used by the web service. For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.

<wsdl:types>
<xsd:schema xmlns:mrm="http://tempuri.org/ms_sOaP" targetNamespace="http://tempuri.org/ms_sOaP" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="org/tempuri/mssoap/DETAILS_HOLDER_WSDLGenWrapper.mxsd"/>
</xsd:schema>
</wsdl:types>

The hi-lighted line indicates where the message definition files are available, this message definition in turn refers to the actual message definition... lets look into the details in the next post....

Message: This can be compared to the method inputs in java, this specifies what exactly should be the input of that particular service, very similar to parameters of a java method, this also describes what is the return message structure and the fault message structure. the below is xml structure displaying the same...


  <wsdl:message name="Operation1_in">
    <wsdl:part element="tns:Request_Details" name="Request_Details"/>
  </wsdl:message>
  <wsdl:message name="Operation1_out">
    <wsdl:part element="tns:Reply" name="Reply"/>
  </wsdl:message>
  <wsdl:message name="Operation1_fault1">
    <wsdl:part element="tns:Fault" name="Fault"/>
  </wsdl:message>


Quick look at the above xml structure will acknowledge us that Request_Details is the actual  message definition we are using as input for the "Operation1" OPERATION[method], and the reply and faults are Reply,Fault respectively.

Thats 2 parts out of 4 from a wsdl lets take a look at the rest of 2 parts i.e. Port-Type & Binding...

Port type: To understand this more easily i will give you an example... consider a java class which has lot of methods and variables defined in it, now, if you want to use the java class you will most probably access it by using its name... thats the same case with Port-Type too... port type defines Operations and their inputs and outputs...
  <wsdl:portType name="ms_sOaPPortType">
    <wsdl:operation name="GetCustomerDetails">
      <wsdl:input message="tns:Operation1_in" name="Operation1_Input"/>
      <wsdl:output message="tns:Operation1_out" name="Operation1_Output"/>
      <wsdl:fault message="tns:Operation1_fault1" name="Operation1_Fault"/>
    </wsdl:operation>
  </wsdl:portType>

GetCustomerDetails is the name, which service consumer will use to get the customer details, internally it is linked to Operation1,  we previously saw  how the xsd files were linked to these operations names.Lets take a look at the remaining part...

Binding: the binding brings together all the parameters we have declared so far... the binding tag has two attributes they are [name,type] any valid string literal can be used in the name and for the type one of the previously declared port type should be used hear.The soap:binding element has two attributes - style and transport. hear we are using HTTP transport, and the binding style is document, there is another binding style which is rpc...
<wsdl:binding name="ms_sOaPSOAP_HTTP_Binding" type="tns:ms_sOaPPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetCustomerDetails">
      <soap:operation soapAction=""/>
      <wsdl:input name="Operation1_Input">
        <soap:body parts="Request_Details" use="literal"/>
      </wsdl:input>
      <wsdl:output name="Operation1_Output">
        <soap:body parts="Reply" use="literal"/>
      </wsdl:output>
      <wsdl:fault name="Operation1_Fault">
        <soap:fault name="Operation1_Fault" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>

the rest of the wsdl:input, wsdl:output, wsdl:fault describe the specific message parts which are used by the web service as input output and fault...

And the last part

<wsdl:service name="ms_sOaPSOAP_HTTP_Service">
    <wsdl:port binding="tns:ms_sOaPSOAP_HTTP_Binding" name="SOAP_HTTP_Port">
      <soap:address location="http://localhost:7800/ms_sOaPSOAP_HTTP_Service"/>
   </wsdl:port>
</wsdl:service>

Binds our binding with an external name by which the end user accesses the service specifies where the service is actually available[Host name] and the port name...Color code is implemented to make it more clear how the elements are linked.... hope you get it.

No comments: