如何在没有代码生成的情况下使用来自 WSDL 的完全填充请求生成 SOAP 消息 [英] How to generate a SOAP message with a fully populated request from WSDL without code gen

查看:13
本文介绍了如何在没有代码生成的情况下使用来自 WSDL 的完全填充请求生成 SOAP 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问您如何基于 WSDL 文件生成 XML 格式的 SOAP 请求/响应.目标平台是 JVM,因此可以使用多种语言(例如 Java、Scala、Groovy、JRuby、Jython 等).SOAP 请求/响应生成应该完全在 XML 级别上完成,没有任何类生成和类加载(WSDL2Java、JAXB 或类似方法在这种情况下是不合适的).生成应该使用开源组件以编程方式完成.生成技术应该支持文档文字、rpc 编码和 rpc 文字风格,因此参数的正确编码应该由生成器处理.请求/响应消息应该完全填充 -> 即使对于空/空白值也应该生成空节点.

I would like to ask you how I can generate a SOAP request/response in a XML format on the basis of the WSDL file. The target platform is JVM so a wide set of languages can be used (e.g. Java, Scala, Groovy, JRuby, Jython, etc.). The SOAP request/response generation should be done purely on the XML level without any class-generation and class-loading (WSDL2Java, JAXB or similar approaches are inappropriate in this case). Generation should be done programmatically with the usage of open-source components. The generation technique should support document-literal, rpc-encoded and rpc-literal flavors, so proper encoding of parameters should be handled by the generator. Request/response messages should be fully-populated -> empty nodes should be generated even for empty/blank values.

长话短说 -> 我想以编程方式做在 SoapUI IDE 中可行的事情.我已经看过不同的 Java 相关库/框架(SAAJ、WSDL4J)或 Ruby(Savon),但我正在努力进一步推动它.

Cutting the long story short -> I would like to do programmatically the thing that is doable in SoapUI IDE. I already had a look at different Java-related libraries/frameworks (SAAJ, WSDL4J) or Ruby (Savon) but I am struggling to move it any further.

我正在处理的示例 Web 服务定义(WSDL 和 XSD)是stockquote-ws.wsdlstockquote-schema.xsd.

A sample Web-Service definition (WSDL and XSD) that I am working on is stockquote-ws.wsdl and stockquote-schema.xsd.

我想做的是:

SoapMessageGenerator generator = new SoapMessageGenerator("stockquote-ws.wsdl");
String request = generator.generateSoapRequest();
String response = generator.generateSoapResponse();

在这种情况下,请求应如下所示:

In this case a request should look like this:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stoc="http://centeractive.com/stockquote.wsdl" xmlns:stoc1="http://centeractive.com/stockquote.xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <stoc:GetLastTradePrice soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <stoc1:TradePriceRequest>
            <tickerSymbol xsi:type="xsd:string">?</tickerSymbol>
         </stoc1:TradePriceRequest>
      </stoc:GetLastTradePrice>
   </soapenv:Body>
</soapenv:Envelope>

... 而响应应该是这样的:

... whereas a response should look like this:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:stoc="http://centeractive.com/stockquote.wsdl" xmlns:stoc1="http://centeractive.com/stockquote.xsd">
   <soapenv:Header/>
   <soapenv:Body>
      <stoc:GetLastTradePriceResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <stoc1:TradePrice>
            <price xsi:type="xsd:float">?</price>
         </stoc1:TradePrice>
      </stoc:GetLastTradePriceResponse>
   </soapenv:Body>
</soapenv:Envelope>

推荐答案

好的.我设法完全解决了这个问题.我从soapUI 中提取了一些代码并启动了一个开源项目,以在Java 中以纯XML 方式支持SOAP.类抽取背后的主要原因是将负责生成 SOAP 消息的代码与与其他模块(如soapUI 图形用户界面等)紧密耦合的其余soapUIs 代码分开.您可以找到项目在这里:https://github.com/reficio/soap-ws 不仅可以生成 SOAP 消息,还提供 SOAP 客户端和服务器.更多详情请见:http://www.reficio.org/projects

OK. I managed to fully solve this problem. I have extracted some code from soapUI and started an open-source project to support SOAP in a purely XML way in Java. The main reason behind the class extraction was to separate the code that is responsible for the generation of the SOAP messages from the rest of the soapUIs code that is tightly coupled with other modules, such as soapUIs graphical user interface, etc. You can find the project here: https://github.com/reficio/soap-ws Not only is it able to generate SOAP messages, but also provides SOAP client and server. More details here: http://www.reficio.org/projects

这篇关于如何在没有代码生成的情况下使用来自 WSDL 的完全填充请求生成 SOAP 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆