2

我有以下引用模式的 wsdl。根据 wsdl,我们可以有以下请求和响应 xml。我想要的是,有两组模式,一组用于请求,一组用于响应 xml。我相信我应该将 trade.wsdl 转换为模式,一个用于请求,一个用于响应。我想使用这些模式集,如果我生成 xml(就像我们在 eclipse 中的选项,从模式生成 xml),我应该能够获得请求和响应 xmls 的相同副本(使用模式集回应)。

有没有办法将 wsdl 转换为模式,一个用于请求,一个用于响应?在这种情况下 trade.wsdl,经过一些修改,我们应该有一个集合,例如 traderequest.xsd(它又引用了 trade.xsd),另一个集合 traderesponse.xsd(它又引用了 trade.xsd)

贸易.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>

贸易.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>

请求 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>

响应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>
4

1 回答 1

1

我认为没有直接的方法可以从 wsdl 生成 xsd 但你可以这样做

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 

请按照此步骤生成 xml 架构。

于 2014-02-13T11:59:33.600 回答