WSDL ,Web Service Definition Language

Sunday, 17 July 2016

WSDL ,Web Service Definition Language

What is WSDL or Web Service Definition Language ?
WSDL is a XML language for describing web service, It is a contract between the service Provider and the client. Since it a XML based language so it is easily readable by human and .Net or Java tools. So any communication between the service provider and the client has to be specify in the form of WSDL. Web service is describe as set of end point and each endpoint are called port. These endpoint or ports are made of two things
1. abstract part
 2. Concrete binding part
This Image will describe the scenario in details.



Why WSDL ?
It enable automation of connection between the partners(Web service,Service Provide and client). WSDL contain details what service available and how to invoke the service in
a presise manner. Machine can also read WSDL and invoke the service define in WSDL.
An Example of WSDL 
<definitions name="StockQuote"
             targetNamespace="http://example.com/stockquote.wsdl"
             xmlns:tns="http://example.com/stockquote.wsdl"
             xmlns:xsd1="http://example.com/stockquote.xsd"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns="http://schemas.xmlsoap.org/wsdl/">
-------------------------------------Types Element----------------------------------
  <types>
    <schema targetNamespace="http://example.com/stockquote.xsd"
            xmlns="http://www.w3.org/2000/10/XMLSchema">
      <element name="TradePriceRequest">
        <complexType>
          <all>
            <element name="tickerSymbol" type="string"/>
          </all>
        </complexType>
      </element>
      <element name="TradePrice">
         <complexType>
           <all>
             <element name="price" type="float"/>
           </all>
         </complexType>
      </element>
    </schema>
  </types>
---------------------------------Message Element-----------------------------------------
  <message name="GetLastTradePriceInput">
    <part name="body" element="xsd1:TradePriceRequest"/>
  </message>

  <message name="GetLastTradePriceOutput">
    <part name="body" element="xsd1:TradePrice"/>
  </message>
---------------------------------Port Types Element--------------------------------------
  <portType name="StockQuotePortType">
----------------------------------Operation--------------------------------------
    <operation name="GetLastTradePrice">
      <input message="tns:GetLastTradePriceInput"/>
      <output message="tns:GetLastTradePriceOutput"/>
    </operation>
---------------------------------------------------------------------------------
  </portType>
-------------------------------Binding Element-------------------------------------------
  <binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>  //this line define communication protocal SOAP over Http.
    <operation name="GetLastTradePrice">
      <soap:operation soapAction="http://example.com/GetLastTradePrice"/>
      <input>
        <soap:body use="literal"/>                              //Encoding Seheme
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
-------------------------------Service Element--------------------------------------------

  <service name="StockQuoteService">
    <documentation>My first service</documentation>
-----------------------------Port Element -------------------------------------------------
    <port name="StockQuotePort" binding="tns:StockQuoteSoapBinding">
      <soap:address location="http://example.com/stockquote"/>
    </port>
  </service>

</definitions>

WSDL Elements 
Abstract part 
  •   Type : Built-in data types and use XMLSchema as type syatem, Use to describe Exchange messages 
  •   Message : A definition of an abstract message that may consist of multiple logical parts, each part                         may be of a different type
  •   Operation : It is the abstract definition of the Action, refers to input and output messages       
 Types of Operation 
1.        One way : Only endpoint receive a message. In this case only  <input                      message="tns:GetLastTradePriceInput"/> will be there in the example.
2.        Request and Response : Only endpoint receive a message and send related             response.  Our example contain this operation. 
3.         Solicit response: A request for a response. (The specific definition for this              action is pending.)
4.         Notification: Messages sent to multiple receivers. (The specific definition               for this action is pending.)
  •   Port Type (Interfaces ): Collection of operation and abstract definition of a service, can be mapped to multiple transports through various bindings.


Concrete binding part

1.     Binding : It is the concrete protocol and data formats for the operations and messages defined for a particular port type.
2.     Port : It is define a single communication end point, combination of a binding and a network address, providing the target address of the service communication
3.     Service : It is a collection of related end-points encompassing the service definitions in the file; the services map the binding to the port and include any extensible definitions.

Now below picture will describe the Web Service invocation