【问题标题】:wsdl to schema conversion for request and response请求和响应的 wsdl 到模式转换
【发布时间】:2012-06-30 20:50:08
【问题描述】:

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

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

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

【问题讨论】:

    标签: xml wsdl schema


    【解决方案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 架构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 2015-12-10
      • 2020-04-11
      • 2016-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多