Suresh
Suresh

Reputation: 1101

wsdl to schema conversion for request and response

I have the below wsdl which references a schema. As per the wsdl we can have the below request and response xml. What i want is, to have two sets of schemas, one for request and one for response xml. I believe i should convert trade.wsdl to a schema, one for request and one for response. I would like to use those sets of schema, if i generate xml(like the option we have in eclipse, generate xml from schema), I should be able to get the same copy of request and the response xmls(using the set of schemas for response).

Is there a way to convert the wsdl to schema, one for request and one for response? In this case trade.wsdl, with some modifications we should have one set, which is like traderequest.xsd(which in turn references trade.xsd), another set traderesponse.xsd(which in turn references trade.xsd)

trade.wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://com.joemo.schema.tradeservice"
    xmlns="http://com.joemo.schema.tradeservice" 
    xmlns:tr="http://com.joemo.schema.trade"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <wsdl:types>
        <xsd:schema targetNamespace="http://com.joemo.schema.tradeservice">
            <xsd:import namespace="http://com.joemo.schema.trade" schemaLocation="trade.xsd" />
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="tradeInput">
        <wsdl:part name="trade" element="tr:trade" />
    </wsdl:message>

    <wsdl:message name="tradeOutput">
        <wsdl:part name="status" element="tr:status" />
    </wsdl:message>

    <wsdl:portType name="TradeService">
        <wsdl:operation name="book">
            <wsdl:input message="tradeInput" />
            <wsdl:output message="tradeOutput" />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="TradeServiceHTTPBinding" type="TradeService">
        <wsdlsoap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="book">
            <wsdlsoap:operation soapAction="" />
            <wsdl:input>
                <wsdlsoap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <wsdlsoap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="TradeServicePorts">
        <wsdl:port binding="TradeServiceHTTPBinding" name="TradeService">
            <wsdlsoap:address
                location="http://localhost:9084/tradeService/TradeServicePorts" />
        </wsdl:port>
    </wsdl:service>

</wsdl:definitions>

trade.xsd

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema targetNamespace="http://com.joemo.schema.trade" xmlns="http://com.joemo.schema.trade"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <!-- web service input types -->

    <xsd:element name="trade">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="security" type="xsd:string" minOccurs="1" maxOccurs="1" />
                <xsd:element name="quantity" type="xsd:integer" minOccurs="1" maxOccurs="1" />
                <xsd:element name="comments" type="comment" minOccurs="1" maxOccurs="unbounded" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="comment">
        <xsd:sequence>
            <xsd:element name="message" type="xsd:string" minOccurs="1" maxOccurs="1" />
            <xsd:element name="author" type="xsd:string" minOccurs="1" maxOccurs="1" />
        </xsd:sequence>
    </xsd:complexType>

    <!-- web service output types -->

    <xsd:element name="status">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="id" type="xsd:string" minOccurs="1" maxOccurs="1" />
                <xsd:element name="message" type="xsd:string" minOccurs="1" maxOccurs="1" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

request xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://com.joemo.schema.trade">
   <soapenv:Header/>
   <soapenv:Body>
      <com:trade>
         <security>?</security>
         <quantity>?</quantity>
         <!--1 or more repetitions:-->
         <comments>
            <message>?</message>
            <author>?</author>
         </comments>
      </com:trade>
   </soapenv:Body>
</soapenv:Envelope>

response xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://com.joemo.schema.trade">
   <soapenv:Header/>
   <soapenv:Body>
      <com:status>
         <id>?</id>
         <message>?</message>
      </com:status>
   </soapenv:Body>
</soapenv:Envelope>

Upvotes: 2

Views: 5049

Answers (1)

sus007
sus007

Reputation: 295

I think there aren't direct way to generate xsd from wsdl but you can do this way

1. Create Request & Response classes , 
2. In Request class defined  request parameter, and In Response class defined response parameter with JAXB annotation
3. Then use this Request & Response class in Endpoint
4. Then We are using JAXB to generate xml schema from Request and Response classes
5. Right click on your Eclipse project -> New -> other -> Schema from Jaxb classes 

Please follow this step and generate xml schema.

Upvotes: 1

Related Questions