Saturday 3 December 2016

WSDL

·         WSDL stands for Web Services Description Language
·         WSDL is an XML based protocol for information exchange in decentralized and distributed environments.
·         WSDL is the standard format for describing a web service.
·         WSDL definition describes how to access a web service and what operations it will perform.
·         WSDL is a language for describing how to interface with XML-based services.
·         WSDL is a language for describing how to interface with XML-based services.


Sample WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<description xmlns="http://www.w3.org/ns/wsdl"
             xmlns:tns="http://www.tmsws.com/wsdl20sample"
             xmlns:whttp="http://schemas.xmlsoap.org/wsdl/http/"
             xmlns:wsoap="http://schemas.xmlsoap.org/wsdl/soap/"
             targetNamespace="http://www.tmsws.com/wsdl20sample">

<!-- Abstract type -->
   <types>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns="http://www.tmsws.com/wsdl20sample"
                targetNamespace="http://www.example.com/wsdl20sample">

         <xs:import namespace=http://www.example.org schemaLocation=”abc.xsd”/>
      </xs:schema>
   </types>

<!-- Abstract interfaces -->
   <interface name="Interface1">
      <fault name="Error1" element="tns:response"/>
      <operation name="Opp1" pattern="http://www.w3.org/ns/wsdl/in-out">
         <input messageLabel="In" element="tns:request"/>
         <output messageLabel="Out" element="tns:response"/>
      </operation>
   </interface>

<!-- Concrete Binding Over HTTP -->
   <binding name="HttpBinding" interface="tns:Interface1"
            type="http://www.w3.org/ns/wsdl/http">
      <operation ref="tns:Get" whttp:method="GET"/>
   </binding>

<!-- Concrete Binding with SOAP-->
   <binding name="SoapBinding" interface="tns:Interface1"
           type="http://www.w3.org/ns/wsdl/soap"
           wsoap:protocol="http://www.w3.org/2003/05/soap/bindings/HTTP/"
           wsoap:mepDefault="http://www.w3.org/2003/05/soap/mep/request-    response">
      <operation ref="tns:Ge99t" />
   </binding>


<!-- Web Service offering endpoints for both bindings-->
   <service name="Service1" interface="tns:Interface1">
      <endpoint name="HttpEndpoint"
                binding="tns:HttpBinding"
                address="http://www.example.com/rest/"/>
      <endpoint name="SoapEndpoint"
                binding="tns:SoapBinding"
                address="http://www.example.com/soap/"/>
   </service>
</description>

WSDL Types Element

A Web service needs to define its inputs and outputs and how they are mapped into and out of services. WSDL <types> elements take care of defining the data types that are used by the web service. Types are XML documents, or document parts.
  <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>


WSDL Message Element

·         The <message> element describes the data being exchanged between the Web service providers and consumers.
·         Each Web Service has two messages: input and output.
·         The input describes the parameters for the Web Service and the output describes the return data from the Web Service.
·         Each message contains zero or more <part> parameters, one for each parameter of the Web Service's function.
·         Each <part> parameter associates with a concrete type defined in the <types>container element.

   <message name="SayHelloRequest">
      <part name="firstName" type="xsd:string"/>
   </message>
   <message name="SayHelloResponse">
      <part name="greeting" type="xsd:string"/>
   </message>

WSDL portType Element

The <portType> element combines multiple message elements to form a complete oneway or round-trip operation.
For example, a <portType> can combine one request and one response message into a single request/response operation. This is most commonly used in SOAP services. A portType can define multiple operations.

Sync WSDL
<portType name="Hello_PortType">
      <operation name="sayHello">
         <input message="tns:SayHelloRequest"/>
         <output message="tns:SayHelloResponse"/>
      </operation>
   </portType>
Async WSDL
<portType name="Hello_PortType">
      <operation name="sayHello">
         <input message="tns:SayHelloRequest"/>
      </operation>
</portType>
<portType name="Hello_PortType">
      <operation name="sayHello">
         <input message="tns:SayHelloRequest"/>
      </operation>
   </portType>

WSDL Binding Element

·         The <binding> element provides specific details on how a portType operation will actually be transmitted over the wire.
·         The bindings can be made available via multiple transports, including HTTP GET, HTTP POST, or SOAP.
·         The bindings provide concrete information on what protocol is being used to transferportType operations.
·         The bindings provide information where the service is located.
·         For SOAP protocol, the binding is <soap:binding>, and the transport is SOAP messages on top of HTTP protocol.
·         You can specify multiple bindings for a single portType.
·         The binding element has two attributes - the name attribute and the type attribute.

  <wsdl:binding name="PrepaidAccountSOAP" type="tns:PrepaidAccount">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>  
 <wsdl:operation name="viewRechBarInfo">
      <soap:operation soapAction="http://www.telenor.mm/PrepaidAccount/viewRechBarInfo"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="QueryAvailableOffers">
      <soap:operation soapAction="http://www.telenor.mm/PrepaidAccount/QueryAvailableOffers"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

WSDL Ports Element

A <port> element defines an individual endpoint by specifying a single address for a binding.
·         The port element has two attributes - the name attribute and the binding attribute.
·         The name attribute provides a unique name among all ports defined within in the enclosing WSDL document.
·         The binding attribute refers to the binding using the linking rules defined by WSDL.
·         Binding extensibility elements (1) are used to specify the address information for the port.
·         A port MUST NOT specify more than one address.
·         A port MUST NOT specify any binding information other than address information.

<service name="Hello_Service">
      <documentation>WSDL File for HelloService</documentation>
      <port binding="tns:Hello_Binding" name="Hello_Port">
         <soap:address
            location="http://www.examples.com/SayHello/">
      </port>
   </service>

WSDL Service Element

·         The <service> element defines the ports supported by the Web service. For each of the supported protocols, there is one port element. The service element is a collection of ports.
·         Web service clients can learn from the service element where to access the service, through which port to access the Web service, and how the communication messages are defined.

·         The service element includes a documentation element to provide human-readable documentation.


Different Types of WSDL

1.       Abstract WSDL : Contain Types, Messages, PortTypes
2.       Concrete WSDL: Contain Types, Messages, PortTypes and Bindings, Services

Different Styles of WSDL

1.       Document
2.       RPC

Document vs RPC
1.       In document style, the SOAP (Simple Object Access Protocol) message is sent as a Single Document whereas in the RPC Style, the SOAP body may contain several elements.
2.       The document style is loosely coupled whereas the RPC is tightly coupled.
3.       In the document style, the client sends the service parameters in simple XML format, whereas in the RPC style, the parameters are sent as discrete of values.
4.       The document style losses the operation name in the SOAP message whereas the RPC style keeps the operation name in the SOAP message.

5.       In the document style, messages can always be validated using any XML validator, whereas in the RPC style, the transformed data is difficult to validate by the SOAP message.

No comments:

Post a Comment