×
☰ See All Chapters

WSDL Tutorial

Web Services Description Language (WSDL) is document provided by the web service provider to explain consumer about the services he is providing. Provider should explain consumer about the services he is providing. To know the services of provider, consumer cannot look into the code of provider. So consumer needs the information like what are the services provided, what they will take as input, and what the output they will return, what URL has to use to get services etc... Provider will explain all these information in one document called "WSDL". "WSDL" stands for Web Service Description Language. "WSDL" is an XML document, because it should be language independent, so that any type of client can understand the services of the "Provider".

In this WSDL tutorial, we are going to learn all the important elements of WSDL document.  Below is the list of the important elements of WSDL.

To understand the WSDL structure we are considering the below sample HelloWorldService WSDL.

<definitions

        xmlns:wsu="https://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"

        xmlns:wsp="https://www.w3.org/ns/ws-policy" xmlns:wsp1_2="https://schemas.xmlsoap.org/ws/2004/09/policy"

        xmlns:wsam="https://www.w3.org/2007/05/addressing/metadata" xmlns:soap="https://schemas.xmlsoap.org/wsdl/soap/"

        xmlns:tns="https://java4coding.com/" xmlns:xsd="https://www.w3.org/2001/XMLSchema"

        xmlns="https://schemas.xmlsoap.org/wsdl/" targetNamespace="https://java4coding.com/"

        name="HelloWorldService">

        <types />

        <message name="getHelloWorldAsString">

                <part name="arg0" type="xsd:string" />

        </message>

        <message name="getHelloWorldAsStringResponse">

                <part name="return" type="xsd:string" />

        </message>

        <portType name="HelloWorld">

                <operation name="getHelloWorldAsString">

                        <input

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringRequest"

                                message="tns:getHelloWorldAsString" />

                        <output

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringResponse"

                                message="tns:getHelloWorldAsStringResponse" />

                </operation>

        </portType>

        <binding name="HelloWorldPortBinding" type="tns:HelloWorld">

                <soap:binding transport="https://schemas.xmlsoap.org/soap/http"

                        style="rpc" />

                <operation name="getHelloWorldAsString">

                        <soap:operation soapAction="" />

                        <input>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </input>

                        <output>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </output>

                </operation>

        </binding>

        <service name="HelloWorldService">

                <port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">

                        <soap:address location="https://localhost:7779/ws/hello" />

                </port>

        </service>

</definitions>

  • The root element of a WSDL document is definitions. So we start the WSDL tree with a definitions node as root. 

wsdl-tutorial-0
 
  • To analyze a WSDL document it is recommended to read it from the bottom upwards. At the bottom of the HelloWorldService’s  WSDL we find a child element of definitions named service. 

<service name="HelloWorldService">

        <port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">

                <soap:address location="https://localhost:7779/ws/hello" />

        </port>

</service>

 

The name of the service is HelloWorldService. A service can have multiple ports. In our example we have one port. Each port describes a way to access the service.

wsdl-tutorial-1
 
  • Let's have a look at the child elements of port 

<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">

        <soap:address location="https://localhost:7779/ws/hello" />

</port>

It's child element address has a different XML prefix than the other elements. Instead of the SOAP binding other bindings for JMS or a file transport can be used. The address element has one attribute named location pointing to an endpoint address of the service.

wsdl-tutorial-2
 
  • The value "tns:HelloWorldPortBinding " points to a binding further up in the document. Each port points to different binding. 

<definitions

… …

… …

… …

        <binding name="HelloWorldPortBinding" type="tns:HelloWorld">

                <soap:binding transport="https://schemas.xmlsoap.org/soap/http"

                        style="rpc" />

                <operation name="getHelloWorldAsString">

                        <soap:operation soapAction="" />

                        <input>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </input>

                        <output>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </output>

                </operation>

        </binding>

        <service name="HelloWorldService">

                <port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">

                        <soap:address location="https://localhost:7779/ws/hello" />

                </port>

        </service>

</definitions>

wsdl-tutorial-3
 
  • A binding provides details about a specific transport. The binding has two different types of children. 

<binding name="HelloWorldPortBinding" type="tns:HelloWorld">

                <soap:binding transport="https://schemas.xmlsoap.org/soap/http" style="rpc" />

                <operation name="getHelloWorldAsString">

                        <soap:operation soapAction="" />

                        <input>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </input>

                        <output>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </output>

                </operation>

</binding>

 

 

wsdl-tutorial-4
 

Value of the transport attribute is an URI that indicates that SOAP messages should be send over HTTP.  

The value "rpc" of the style attribute gives us a clue about the message style together with the use attribute of the soap:body elements. In our example we have a literal message style.
A binding can specify different transport options for each method of a service.

  • Inside the wsdl:operation element we have “soap:operation”, “input”, “output”. soap:operation element gives details for the SOAP protocol and its transport. The soapAction attribute is a reminiscent from the past. The Basic Profile of the Web Services Interoperability Organization stipulates that the soapAction should be used with a fixed value of an empty string. 

<operation name="getHelloWorldAsString">

        <soap:operation soapAction="" />

        <input>

                <soap:body use="literal" namespace="https://hassan.manum.com/" />

        </input>

        <output>

                <soap:body use="literal" namespace="https://hassan.manum.com/" />

        </output>

</operation>  

wsdl-tutorial-5
 
  • The soap:body and soap:header elements of input and output can describe a message further. (soap:header  is optional) In the example the style is always literal. 

The value "rpc" of the style attribute gives us a clue about the message style together with the use attribute of the soap:body elements. In our example we have a literal message style.

wsdl-tutorial-6
 
  • Let us move further up in the WSDL. Value of the type attribute of the binding tag points to a portType with the same name further up in the document. 

<portType name="HelloWorld">

                <operation name="getHelloWorldAsString">

                        <input

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringRequest"

                                message="tns:getHelloWorldAsString" />

                        <output

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringResponse"

                                message="tns:getHelloWorldAsStringResponse" />

                </operation>

        </portType>

        <binding name="HelloWorldPortBinding" type="tns:HelloWorld">

                <soap:binding transport="https://schemas.xmlsoap.org/soap/http"

                        style="rpc" />

                <operation name="getHelloWorldAsString">

                        <soap:operation soapAction="" />

                        <input>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </input>

                        <output>

                                <soap:body use="literal" namespace="https://java4coding.com/" />

                        </output>

                </operation>

        </binding>

 

 

wsdl-tutorial-7
 
  • The tag portType is present only in WSDL 1.1 which is similar to the interface tag of WSDL 2.0. In WSDL 2.0 the term portType is replaced with the term interface. 

An interface can have several operations. An operation corresponds to a method in java programming. (function in other procedural programming.)

The WSDL of the HelloWorldService has only one portType.  

wsdl-tutorial-8
 
  • Child tag of portType tag is operation tag as in the binding. But here the input and output describe the structure of the messages not transport specific options.   

<portType name="HelloWorld">

                <operation name="getHelloWorldAsString">

                        <input

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringRequest"

                                message="tns:getHelloWorldAsString" />

                        <output

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringResponse"

                                message="tns:getHelloWorldAsStringResponse" />

                </operation>

        </portType>

 

wsdl-tutorial-9
 
  • The input and output tags has message attribute which refers message tags again up in the WSDL document. 

<message name="getHelloWorldAsString">

                <part name="arg0" type="xsd:string" />

        </message>

        <message name="getHelloWorldAsStringResponse">

                <part name="return" type="xsd:string" />

        </message>

        <portType name="HelloWorld">

                <operation name="getHelloWorldAsString">

                        <input

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringRequest"

                                message="tns:getHelloWorldAsString" />

                        <output

                                wsam:Action="https://java4coding.com/HelloWorld/getHelloWorldAsStringResponse"

                                message="tns:getHelloWorldAsStringResponse" />

                </operation>

        </portType>

wsdl-tutorial-10
 
  • The message tag has one part element as child. The part element and its attributes represent the java methods (function in other procedural programming) return vale and parameters. 

wsdl-tutorial-11
 
wsdl-tutorial-12
 
  • The types element can have multiple XML schemas as children. If the web service is accepting/returning basic primitive type this types tag will be empty. Let us consider the return type as Person class object, now types tag will have xml schema pointing to Person xsd/dtd document. 

<types>

        <xsd:schema>

                <xsd:import namespace=https://java4coding.com/ schemaLocation="https://localhost:7779/ws/person?xsd=1" />

        </xsd:schema>

</types>

The corresponding xsd document (https://localhost:7779/ws/person?xsd=1) is given below:

<xs:schema xmlns:xs="https://www.w3.org/2001/XMLSchema"

        version="1.0" targetNamespace="https://hassan.manum.com/">

        <xs:complexType name="person">

                <xs:sequence>

                        <xs:element name="age" type="xs:int" />

                        <xs:element name="id" type="xs:int" />

                        <xs:element name="name" type="xs:string" minOccurs="0" />

                </xs:sequence>

        </xs:complexType>

</xs:schema>

 

 

wsdl-tutorial-13
 

All Chapters
Author