Wednesday, July 20, 2011

MULE HTTP Web Service - Step1. Creating WSDL

The following example deals with the creation of a web service named "ShippingService" and it exposes two methods "orderShipment" and "getShipmentInfo"

In Step 1, we will be creating the WSDL and the XSD.

ShippingService.xsd

The ShippingService XSD was created using Eclipse and it contains the request and the response objects that will be used for creating the web service.
It uses the namespace: http://shippingservice.services.com

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://shippingservice.services.com"
    xmlns:tns="http://shippingservice.services.com" elementFormDefault="qualified">

    <complexType name="OrderShippingRequest">
        <sequence>
            <element name="orderNo" type="string"></element>
            <element name="price" type="double"></element>
            <element name="itemNo" type="string"></element>
            <element name="itemQty" type="int"></element>
            <element name="shipmentType" type="tns:ShipmentType"></element>
        </sequence>

    </complexType>

    <simpleType name="ShipmentType">
        <restriction base="string">
            <enumeration value="EXPRESS"></enumeration>
            <enumeration value="FAST"></enumeration>
            <enumeration value="NORMAL"></enumeration>
        </restriction>
    </simpleType>

    <complexType name="OrderShippingResponse">
        <sequence>
            <element name="confirmationNo" type="string"></element>
            <element name="estimatedDate" type="string"></element>
        </sequence>
    </complexType>

    <element name="OrderShippingRequest" type="tns:OrderShippingRequest">
    </element>

    <element name="OrderShippingResponse" type="tns:OrderShippingResponse">
    </element>

    <complexType name="GetShippingInfoRequest">
        <sequence>
            <element name="confirmationNo" type="string"></element>
        </sequence>
    </complexType>

    <complexType name="GetShippingInfoResponse">
        <sequence>
            <element name="orderNo" type="string"></element>
            <element name="estimatedDeliveryDate" type="string"></element>
            <element name="currentStatus" type="string"></element>
        </sequence>
    </complexType>

    <element name="GetShippingInfoRequest" type="tns:GetShippingInfoRequest">
    </element>

    <element name="GetShippingInfoResponse" type="tns:GetShippingInfoResponse">
    </element>
</schema>


ShippingService.wsdl

This WSDL exposes two different methods getShippingInfo and orderShipment.
It uses the namespace: http://webservice.shippingservice.services.com

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://webservice.shippingservice.services.com"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    name="ShippingService" targetNamespace="http://webservice.shippingservice.services.com"
    xmlns:xsd1="http://shippingservice.services.com">
    <wsdl:types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:import namespace="http://shippingservice.services.com"
                schemaLocation="ShippingService.xsd">
            </xsd:import>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="getShippingInfoRequest">
        <wsdl:part element="xsd1:GetShippingInfoRequest" name="request" />
    </wsdl:message>
    <wsdl:message name="getShippingInfoResponse">
        <wsdl:part element="xsd1:GetShippingInfoResponse"
            name="response" />
    </wsdl:message>
    <wsdl:message name="orderShippingRequest">
        <wsdl:part name="request" element="xsd1:OrderShippingRequest"></wsdl:part>
    </wsdl:message>
    <wsdl:message name="orderShippingResponse">
        <wsdl:part name="response" element="xsd1:OrderShippingResponse"></wsdl:part>
    </wsdl:message>
    <wsdl:portType name="ShippingService">
        <wsdl:operation name="getShippingInfo">
            <wsdl:documentation>This method is used to retrieve the
                status of a particular shipping info
            </wsdl:documentation>
            <wsdl:input message="tns:getShippingInfoRequest" />
            <wsdl:output message="tns:getShippingInfoResponse" />
        </wsdl:operation>
        <wsdl:operation name="orderShipping">
            <wsdl:documentation>This method is used to make an order
                for shipment</wsdl:documentation>
            <wsdl:input message="tns:orderShippingRequest"></wsdl:input>
            <wsdl:output message="tns:orderShippingResponse"></wsdl:output>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="ShippingServiceSOAP" type="tns:ShippingService">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="getShippingInfo">
            <soap:operation
                soapAction="http://webservice.shippingservice.services.com/NewOperation" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="ShippingService">
        <wsdl:port binding="tns:ShippingServiceSOAP" name="ShippingServiceSOAP">
            <soap:address location="http://www.example.org/" />
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>


No comments:

Post a Comment