我想解析一个WSDL以获取操作,端点和示例负载。 WSDL由用户输入。我无法找到一个教程来做到这一点。解析WSDL的简单方法
我只能找到那些生成我不需要的源代码。我试过使用XBeans,但显然我需要撒克逊。有没有一个简单的轻量级方法来做到这一点,没有撒克逊?
E.g.
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace=
"http://example.com/stockquote.wsdl"
xmlns:tns="http://example.com/stockquote.wsdl"
xmlns:xsd1="http://example.com/stockquote.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace=
"http://example.com/stockquote.xsd"
xmlns="http://www.w3.org/2000/10/XMLSchema">
<element name="TradePriceRequest">
<complexType>
<all>
<element name="tickerSymbol"
type="string"/>
</all>
</complexType>
</element>
<element name="TradePrice">
<complexType>
<all>
<element name="price" type="float"/>
</all>
</complexType>
</element>
</schema>
</types>
<message name="GetLastTradePriceInput">
<part name="body" element=
"xsd1:TradePriceRequest"/>
</message>
<message name="GetLastTradePriceOutput">
<part name="body" element="xsd1:TradePrice"/>
</message>
<portType name="StockQuotePortType">
<operation name="GetLastTradePrice">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</portType>
<binding name="StockQuoteSoapBinding"
type="tns:StockQuotePortType">
<soap:binding style="document"
transport=
"http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetLastTradePrice">
<soap:operation
soapAction=
"http://example.com/GetLastTradePrice"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort"
binding="tns:StockQuoteBinding">
<soap:address location=
"http://example.com/stockquote"/>
</port>
</service>
</definitions>
应该得到操作:GetLastTradePrice,GetLastTradePrice
端点:StockQuotePort
样品有效载荷:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stoc="http://example.com/stockquote.xsd">
<soapenv:Header/>
<soapenv:Body>
<stoc:TradePriceRequest/>
</soapenv:Body>
</soapenv:Envelope>
这像什么呢了SoapUI。但我主要关心的是能否解析WSDL。更多的上下文是上传WSDL,然后结果显示在GWT应用程序中(文件上传必须转到servlet)。所以我需要解析这个文件并创建一个GWT能够理解的对象。
有一个例子wsdl? –
可以使用XML解析器分析wsdl以获取您需要的内容。 SAX非常轻便,学习起来很轻松。看到http://stackoverflow.com/questions/2134507/fast-lightweight-xml-parser – Pedantic
好像你正在寻找图书馆可以做的伎俩。 SOAPUI有一些你可以重用的库。我不记得jar/class的名字,但是我在1年前成功地完成了它。 – Abhilash