Web Service WSDL Easily Explained


  • Web Services Description Language.
  • WSDL is an XML format for describing network services.
  • In General, WSDL is an XML-based language for describing Web services and how to access them.

A WSDL document uses the following elements in the definition of network services
  • Types- Used to describe the data types of messages that are exchanged.
  • Message- Data being transmitted(input parameters, output result, etc).
  • Operations- Methods supported by the service.
  • PortType- Set of operations.
  • Binding- a concrete protocol and data format specification for a particular port type.
  • Port- a single endpoint for communicating with service.
  • Service- a collection of related post.

WSDl XML contains :


Easy Example:

Note: Just go on reading the comments, and you will get everything in code

The example is taken from http://www.w3.org/TR/wsdl and is easily explained below...

//The first line says that it is an XML file
<?xml version="1.0"?>
//Root element is <definitions>, defining your web service till </definitions>
//This list the namespaces that you are following in webservice description
<definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl"
//----------------------- TYPES
    //Name the data items and their types that will
    // be passed in request and response messages
       <schema targetNamespace="http://example.com/stockquote.xsd"
           <element name="TradePriceRequest">
//Some tickerSymbol variable of type string
                //named as TradePriceRequest
                //Here, don't know, whether input parameter or return result
                      <element name="tickerSymbol" type="string"/>
           <element name="TradePrice">
//Some price variable of type float named as TradePrice
                //Here, don't know, whether input parameter or return result
                      <element name="price" type="float"/>

//----------------------- MESSAGES
    //Messages are all request parameters and response results
    //Here the message holds TradePriceRequest element
    //Now, what is TradePriceRequest element?
    //See, the defination in <types><element></element></types> above
<message name="GetLastTradePriceInput">
       <part name="body" element="xsd1:TradePriceRequest"/>
    //Here the message holds some TradePrice element
    //Now, what is TradePrice element?
    //See, the defination in <types><element></element></types> above
    <message name="GetLastTradePriceOutput">
       <part name="body" element="xsd1:TradePrice"/>
//----------------------- PORTTYPE
    //Mention the operations(methods) in webservice
    //All operations are bind to a portType
<portType name="StockQuotePortType">
    //Here, service supports only 1 operation - GetLastTradePrice
    //Input: ticker symbol of type string
    //Output: price as a float
        <operation name="GetLastTradePrice">
               <input message="tns:GetLastTradePriceInput"/>
               <output message="tns:GetLastTradePriceOutput"/>
         //Here, you can mention second operation
         <operation name="_______">
               <input message="tns:_______"/>
               <output message="tns:_______"/>
         //Here, third operation and so on
//----------------------- BINDING
    //Binding is a concrete protocol and
    //data format specification for a particular port type
    <binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
//type of protocol used to call webservice
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="GetLastTradePrice">
//Below lines defines the address of the operation
           <soap:operation soapAction="http://example.com/GetLastTradePrice"/>
               <soap:body use="literal"/>
//Its input
               <soap:body use="literal"/>
//Its output

//----------------------- SERVICE
    //A service groups a set of related ports together:
    <service name="StockQuoteService"> //unique name of service
        <documentation>My first service</documentation>
//port specifies onw and only one address/endpoint for binding
        <port name="StockQuotePort" binding="tns:StockQuoteBinding">
           //location defines the address of your service
           <soap:address location="http://example.com/stockquote"/>




Happy learning....