I had been looking for few WSDL examples that I could use as sample while creating my own WSDL for a web service. But I could not find an example that could meet my need completely. So, in this post we will look at various WSDL examples and then create one for a 3GPP notification service (as defined in 3GPP TS 29.335). Then we will create and deploy a web service and create a SOAP client to test it out in few easy steps using eclipse. This sample web service would hopefully give you all a very good idea on how to do it yourself.

What is WSDL

The Web Services Description Language or WSDL for short describes a the Web service interface. It consists of messages that are exchanged between the client and server. The messages are described abstractly and then bound to a concrete network protocol and message format. Web service definitions can be mapped to any implementation language, platform, object model, or messaging system.

WSDL Example Tutorial Test Sample SOAP Web Service WSDLWSDL Elements

Definition

This contains the attribute name, which in turn has the web service name.

Types

This element uses the XML schema language to declare complex data types and elements that are used elsewhere in the WSDL document.

Message

This element describes the message’s payload using XML schema built-in types, complex types.

PortType/Interface and Operation

These elements describe a Web service’s interface and define its methods.

Binding

This element assigns a portType and its operation elements to a particular protocol (for instance, SOAP 1.1) and encoding style.

Service

This element is responsible for assigning an Internet address to a specific binding.

 

WSDL Example 1

Web Service Name : WebServiceOne

This WSDL example contains:

– SOAP Protocol

– Document Literal Binding

– No optional SOAP Header included in WSDL

– SOAP Body

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.teknocrat.com/WebServiceOne/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WebServiceOne"
targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <wsdl:types>

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <xsd:element name="WebServiceOneOperation">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="in" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element>
    <xsd:element name="WebServiceOneOperationResponse">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="out" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element></xsd:schema></wsdl:types>
    <wsdl:message name="WebServiceOneOperationRequest">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperation"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="WebServiceOneOperationResponse">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperationResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:porttype name="WebServiceOnePortType">
        <wsdl:operation name="WebServiceOneOperation">
            <wsdl:input message="tns:WebServiceOneOperationRequest"></wsdl:input>
            <wsdl:output message="tns:WebServiceOneOperationResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:porttype>
    <wsdl:binding name="WebServiceOneBinding" type="tns:WebServiceOnePortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="WebServiceOneOperation">
            <soap:operation soapaction="http://www.teknocrat.com/WebServiceOne/WebServiceOneOperation" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="WebServiceOne">
        <wsdl:port name="WebServiceOnePort" binding="tns:WebServiceOneBinding">
            <soap:address location="http://www.teknocrat.com/" />
        </wsdl:port>
    </wsdl:service></wsdl:definitions>

WSDL Example 2

Web Service Name : WebServiceOne

This WSDL example contains:

– SOAP Protocol

– RPC Literal Binding

– No optional SOAP Header included in WSDL

– SOAP Body

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.teknocrat.com/WebServiceOne/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WebServiceOne"
targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <wsdl:types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <xsd:element name="WebServiceOneOperation">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="in" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element>
    <xsd:element name="WebServiceOneOperationResponse">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="out" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element></xsd:schema></wsdl:types>
    <wsdl:message name="WebServiceOneOperationRequest">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperation"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="WebServiceOneOperationResponse">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperationResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:porttype name="WebServiceOnePortType">
        <wsdl:operation name="WebServiceOneOperation">
            <wsdl:input message="tns:WebServiceOneOperationRequest"></wsdl:input>
            <wsdl:output message="tns:WebServiceOneOperationResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:porttype>
    <wsdl:binding name="WebServiceOneBinding" type="tns:WebServiceOnePortType"> 

        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="WebServiceOneOperation"> 

            <soap:operation soapaction="http://www.teknocrat.com/WebServiceOne/WebServiceOneOperation" />
            <wsdl:input> 

                <soap:body use="literal" namespace="http://www.teknocrat.com/WebServiceOne/" />
            </wsdl:input>
            <wsdl:output> 

                <soap:body use="literal" namespace="http://www.teknocrat.com/WebServiceOne/" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="WebServiceOne">
        <wsdl:port name="WebServiceOnePort" binding="tns:WebServiceOneBinding">
            <soap:address location="http://www.teknocrat.com/" />
        </wsdl:port>
    </wsdl:service></wsdl:definitions>

WSDL Example 3

Web Service Name : WebServiceOne

This WSDL example contains:

– SOAP Protocol

– RPC Encoded Binding

– No optional SOAP Header included in WSDL

– SOAP Body

<?xml version="1.0" encoding="UTF-8"?>
 <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.teknocrat.com/WebServiceOne/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WebServiceOne"
targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <wsdl:types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <xsd:element name="WebServiceOneOperation">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="in" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element>
    <xsd:element name="WebServiceOneOperationResponse">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="out" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element></xsd:schema></wsdl:types>
    <wsdl:message name="WebServiceOneOperationRequest">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperation"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="WebServiceOneOperationResponse">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperationResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:porttype name="WebServiceOnePortType">
        <wsdl:operation name="WebServiceOneOperation">
            <wsdl:input message="tns:WebServiceOneOperationRequest"></wsdl:input>
            <wsdl:output message="tns:WebServiceOneOperationResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:porttype>
    <wsdl:binding name="WebServiceOneBinding" type="tns:WebServiceOnePortType"> 

        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="WebServiceOneOperation"> 

            <soap:operation soapaction="http://www.teknocrat.com/WebServiceOne/WebServiceOneOperation" />
            <wsdl:input> 

                <soap:body use="encoded" namespace="http://www.teknocrat.com/WebServiceOne/" encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </wsdl:input>
            <wsdl:output> 

                <soap:body use="encoded" namespace="http://www.teknocrat.com/WebServiceOne/" encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="WebServiceOne">
        <wsdl:port name="WebServiceOnePort" binding="tns:WebServiceOneBinding">
            <soap:address location="http://www.teknocrat.com/" />
        </wsdl:port>
    </wsdl:service></wsdl:definitions>

WSDL Example 4

Web Service Name : WebServiceOne

This WSDL example contains:

– HTTP Protocol

– GET Binding

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.teknocrat.com/WebServiceOne/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WebServiceOne"
targetnamespace="http://www.teknocrat.com/WebServiceOne/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
    <wsdl:types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <xsd:element name="WebServiceOneOperation">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="in" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element>
    <xsd:element name="WebServiceOneOperationResponse">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="out" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element></xsd:schema></wsdl:types>
    <wsdl:message name="WebServiceOneOperationRequest">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperation"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="WebServiceOneOperationResponse">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperationResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:porttype name="WebServiceOnePortType">
        <wsdl:operation name="WebServiceOneOperation">
            <wsdl:input message="tns:WebServiceOneOperationRequest"></wsdl:input>
            <wsdl:output message="tns:WebServiceOneOperationResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:porttype>
    <wsdl:binding name="WebServiceOneBinding" type="tns:WebServiceOnePortType"> 

        <http:binding verb="GET" />
        <wsdl:operation name="WebServiceOneOperation"> 

            <http:operation location="/WebServiceOneOperation" />
            <wsdl:input> 

                <http:urlencoded />
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" /> 

            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="WebServiceOne">
        <wsdl:port name="WebServiceOnePort" binding="tns:WebServiceOneBinding"> 

            <http:address location="http://www.teknocrat.com/" />
        </wsdl:port>
    </wsdl:service></wsdl:definitions>

WSDL Example 5

Web Service Name : WebServiceOne

This WSDL example contains:

– HTTP Protocol

– POST Binding

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.teknocrat.com/WebServiceOne/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="WebServiceOne"
targetnamespace="http://www.teknocrat.com/WebServiceOne/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/">
    <wsdl:types><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetnamespace="http://www.teknocrat.com/WebServiceOne/">
    <xsd:element name="WebServiceOneOperation">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="in" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element>
    <xsd:element name="WebServiceOneOperationResponse">
        <xsd:complextype>
            <xsd:sequence> 

                <xsd:element name="out" type="xsd:string"></xsd:element>
            </xsd:sequence>
        </xsd:complextype>
    </xsd:element></xsd:schema></wsdl:types>
    <wsdl:message name="WebServiceOneOperationRequest">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperation"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="WebServiceOneOperationResponse">
        <wsdl:part name="parameters" element="tns:WebServiceOneOperationResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:porttype name="WebServiceOnePortType">
        <wsdl:operation name="WebServiceOneOperation">
            <wsdl:input message="tns:WebServiceOneOperationRequest"></wsdl:input>
            <wsdl:output message="tns:WebServiceOneOperationResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:porttype>
    <wsdl:binding name="WebServiceOneBinding" type="tns:WebServiceOnePortType"> 

        <http:binding verb="POST" />
        <wsdl:operation name="WebServiceOneOperation"> 

            <http:operation location="/WebServiceOneOperation" />
            <wsdl:input>
                <mime:content type="application/x-www-form-urlencoded" /> 

            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" /> 

            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="WebServiceOne">
        <wsdl:port name="WebServiceOnePort" binding="tns:WebServiceOneBinding"> 

            <http:address location="http://www.teknocrat.com/" />
        </wsdl:port>
    </wsdl:service></wsdl:definitions>

WSDL Example 6

Finally this is the WSDL I wanted to finally build. This is bit more complex but structure remains the same.

Web Service Name : Notification (as defined in 3GPP TS 29.335)

This WSDL example contains:

– SOAP Protocol

– Document Literal Binding

– Optional SOAP Header included in WSDL

– SOAP Body

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="notification"
targetnamespace="http://www.3gpp.org/udc/notification"
xmlns="http://www.3gpp.org/udc/notification"> 

    <wsdl:types> 

        <xs:schema targetnamespace="http://www.3gpp.org/udc/notification" xmlns="http://www.3gpp.org/udc/notification" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementformdefault="qualified"> 

            <xs:simpletype name="operationType">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="add" />
                    <xs:enumeration value="modify" />
                    <xs:enumeration value="delete" />
                </xs:restriction>
            </xs:simpletype> 

            <xs:simpletype name="modificationType">
                <xs:restriction base="xs:string">
                    <xs:enumeration value="add" />
                    <xs:enumeration value="replace" />
                    <xs:enumeration value="delete" />
                    <xs:enumeration value="none" />
                </xs:restriction>
            </xs:simpletype> 

            <xs:element name="object">
                <xs:complextype>
                    <xs:sequence>
                        <xs:element ref="attribute" minoccurs="0" maxoccurs="unbounded" />
                    </xs:sequence>
                    <xs:attribute name="objectClass" type="xs:string" />
                    <xs:attribute name="DN" type="xs:string" />
                    <xs:attribute name="operation" type="operationType" use="required" />
                </xs:complextype>
            </xs:element> 

            <xs:element name="attribute">
                <xs:complextype>
                    <xs:choice>
                        <xs:element name="currentValue" type="xs:string" minoccurs="0" maxoccurs="unbounded" />
                        <xs:sequence>
                            <xs:element name="beforeValue" type="xs:string" minoccurs="0" maxoccurs="unbounded" />
                            <xs:element name="afterValue" type="xs:string" minoccurs="0" maxoccurs="unbounded" />
                        </xs:sequence>
                    </xs:choice>
                    <xs:attribute name="name" type="xs:string" use="required" /> 

                    <xs:attribute name="modification" type="modificationType" use="required" />
                </xs:complextype>
            </xs:element> 

            <xs:element name="CorrelationHeader">
                <xs:complextype>
                    <xs:sequence>
                        <xs:element name="serviceName" type="xs:string" minoccurs="0" maxoccurs="1" />
                        <xs:element name="msgId" type="xs:int" minoccurs="1" maxoccurs="1" />
                        <xs:element name="connId" type="xs:int" minoccurs="0" maxoccurs="1" />
                    </xs:sequence>
                </xs:complextype>
            </xs:element> 

            <xs:element name="Notification">
                <xs:complextype>
                    <xs:sequence>
                        <xs:element ref="object" maxoccurs="unbounded" />
                    </xs:sequence>
                </xs:complextype>
            </xs:element> 

            <xs:element name="NotificationResponse" type="xs:string">
           </xs:element>
        </xs:schema>
    </wsdl:types> 

    <wsdl:message name="Header">
        <wsdl:part name="Header" element="CorrelationHeader"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="NotifyRequest">
        <wsdl:part name="Subrecord" element="Notification"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="NotifyResponse">
        <wsdl:part name="Subrecord" element="NotificationResponse"></wsdl:part>
    </wsdl:message> 

    <wsdl:porttype name="NotifyPortType">
        <wsdl:operation name="Notify">
            <wsdl:input message="NotifyRequest">
            </wsdl:input>
            <wsdl:output message="NotifyResponse">
            </wsdl:output>
        </wsdl:operation>
    </wsdl:porttype> 

    <wsdl:binding name="NotifyBinding" type="NotifyPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="Notify">
            <soap:operation soapaction="http://www.3gpp.org/udc/notification/Notification" />
            <wsdl:input>
                <soap:header message="Header" use="literal" part="Header" />
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:header message="Header" use="literal" part="Header" />
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="NotifyService">
        <wsdl:port name="NotifyPort" binding="NotifyBinding">
            <soap:address location="http://localhost/WebServiceProject/services/NotifyPort" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Testing a WSDL using eclipse

1. Start eclipse in JAVA EE perspective.
2. Create a new project.
3. Add the WSDL file to it. (Lets call it notify.wsdl)


4. Right click on the WSDL file and select “Validate”. This should help you identify any issue with the WSDL.
5. Then again right click on the WSDL and pick Web Services -> Generate Java Bean Skeleton.

 

 

6. Now make sure you have set the bar to Test Service. (You need to have Tomcat for this as an eclipse plug-in)

7. Then Press finish.

 

 

8.  This should open a new screen as above. Now all you need to do is send the web service request from screen on top right.


Tags: