我有以下wsdl引用架构。根据wsdl,我们可以得到以下请求和响应xml。我想要的是,有两组模式,一组用于请求,一组用于响应xml。我相信我应该将trade.wsdl转换为模式,一个用于请求,一个用于响应。我想使用那些模式集,如果我生成xml(就像我们在eclipse中的选项,从模式生成xml),我应该能够获得相同的请求副本和响应xmls(使用模式集)回应)。
有没有办法将wsdl转换为schema,一个用于请求,一个用于响应? 在这种情况下,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>
答案 0 :(得分: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架构。