简体   繁体   English

如何使用WSDL完全填充的请求生成SOAP消息,而无需代码生成

[英]How to generate a SOAP message with a fully populated request from WSDL without code gen

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. 我想问你如何在WSDL文件的基础上以XML格式生成SOAP请求/响应。 The target platform is JVM so a wide set of languages can be used (eg Java, Scala, Groovy, JRuby, Jython, etc.). 目标平台是JVM,因此可以使用多种语言(例如Java,Scala,Groovy,JRuby,Jython等)。 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). SOAP请求/响应生成应该完全在XML级别上完成,而不需要任何类生成和类加载(在这种情况下,WSDL2Java,JAXB或类似方法是不合适的)。 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. 生成技术应该支持document-literal,rpc-encoded和rpc-literal风格,因此生成器应该处理参数的正确编码。 Request/response messages should be fully-populated -> empty nodes should be generated even for empty/blank values. 请求/响应消息应该是完全填充的 - >即使对于空/空值,也应生成空节点。

Cutting the long story short -> I would like to do programmatically the thing that is doable in SoapUI IDE. 长话短说 - >我想以编程方式完成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. 我已经看过不同的Java相关库/框架(SAAJ,WSDL4J)或Ruby(Savon),但我正在努力进一步推动它。

A sample Web-Service definition (WSDL and XSD) that I am working on is stockquote-ws.wsdl and stockquote-schema.xsd . 我正在处理的示例Web服务定义(WSDL和XSD)是stockquote-ws.wsdlstockquote-schema.xsd

What I would like to do is: 我想做的是:

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>

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. 我从soapUI中提取了一些代码,并启动了一个开源项目,以Java中的纯XML方式支持SOAP。 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. 类提取背后的主要原因是将负责生成SOAP消息的代码与其他soapUIs代码分开,这些代码与其他模块紧密耦合,例如soapUIs图形用户界面等。您可以找到项目在这里: https//github.com/reficio/soap-ws它不仅能够生成SOAP消息,还提供SOAP客户端和服务器。 More details here: http://www.reficio.org/projects 更多细节: http//www.reficio.org/projects

What about the SOAPUI library: 那么SOAPUI库:

package com.bbog.soap;

import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlOperation;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
import com.eviware.soapui.model.iface.Operation;

public class WsdlAnalyzer {

    public static void main(String[] args) throws Exception {
        WsdlProject project = new WsdlProject();
        WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://localhost:7000/Solicitud?wsdl");
        WsdlInterface wsdl = wsdls[0];
        for (Operation operation : wsdl.getOperationList()) {
            WsdlOperation op = (WsdlOperation) operation;
            System.out.println("OP:"+op.getName());
            System.out.println(op.createRequest(true));
            System.out.println("Response:");
            System.out.println(op.createResponse(true));
        }
    }
}

I am actually looking to do the same thing. 我其实想要做同样的事情。 I've been using the javax.wsdl API to pull information from the wsdl and I'm trying to use javax.xml.soap API to create the SOAP request/response. 我一直在使用javax.wsdl API从wsdl中提取信息,我正在尝试使用javax.xml.soap API来创建SOAP请求/响应。 They might be worth taking a look at. 他们可能值得一看。

You might be interested in kSOAP project which is used in mobile development. 您可能对用于移动开发的kSOAP项目感兴趣。 The following kSOAP tutorial will point you to how to serialize the request and the following section show you how to get the response. 以下kSOAP教程指导您如何序列化请求,以下部分将向您展示如何获取响应。

kSOAP could create the SOAP message without having to generate the proxy code. kSOAP可以创建SOAP消息而无需生成代理代码。 This is needed in mobile development due to its processing power that is considerably less than the desktop and having proxy classes and library are considered heavier than directly creating the SOAP message 这在移动开发中是必需的,因为它的处理能力远低于桌面,并且代理类和库被认为比直接创建SOAP消息更重

IBM article IBM文章

The above article seems to address the technique that I would try for your case: make use of XSLT transformation. 上面的文章似乎解决了我将针对您的情况尝试的技术:使用XSLT转换。 After all you're going from XML to XML. 毕竟你要从XML转向XML。 If you have better luck than I finding (or developing of course) the specific XSLT stylesheet(s) that you need to go from a WSDL to accompanying SOAP request(s) I'd love to learn about it. 如果你有比我找到(或开发当然)更好的运气,你需要从WSDL到随附的SOAP请求的特定XSLT样式表,我很乐意了解它。

Cheers, Wim 干杯,Wim

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM