将 WSDL 转换为其各自的 HTTP 绑定 [英] Convert a WSDL to its respective HTTP Bindings

查看:92
本文介绍了将 WSDL 转换为其各自的 HTTP 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想将 WSDl 转换为来自 WSDL 提供的数据的许多不同的 HTTP 请求.我已经阅读了大量类似的问题,但没有一个真正提供答案.

I'm simply trying to convert a WSDl into a number of different HTTP-requests from data supplied by the WSDL. I have read through a ton of similar questions, but none really provided an answer.

有人说要使用 SOAPUI - 我熟悉这个应用程序并且确实在使用它.但是我需要自己从 WSDL 创建这些 HTTP 请求.

Some say to use SOAPUI - I am familiar with this application and do use it. But I need to create these HTTP-requests from the WSDL on my own.

有人说要尝试 JAXWS - 我查看了许多关于此以及 Axis 的教程,这些教程将 WSDL 转换为 Java 类绑定,您可以使用这些教程测试 Web 服务的方法.我真的很想自己生成 HTTP 请求,以便在某一时刻我可以操纵请求并发送我自己的测试.

Some say to try JAXWS - I looked at a number of tutorials on this as well as on Axis and these translate the WSDL into Java class bindings and you use those methods to test the web services. I really would like to just generate the HTTP-request myself so that at one point I can manipulate the request and send my own tests.

我开始使用 wsdl4j 开始自己解析 WSDL,但我宁愿不走这条路,直到我绝对确定我没有重新发明轮子.在我看来,过去需要这样做吗?但是对于 WSDL4J 和所有其他库,我看不到 WSDL 到 Soap 消息的转换.

I started using wsdl4j to begin parsing the WSDL myself but would rather not go down this path until I'm absolutely sure I'm not reinventing the wheel. Seems to me there has been a need for this in past? But with WSDL4J and every other library I do not see a WSDL to Soap message translation.

任何建议都会非常有帮助.目标是我希望能够获取 WSDL,检查它并为 WSDL 中的每个方法创建 HTTP-SOAP 请求,并且能够测试它们的安全问题.第一步是创建这些请求!

Any suggestions would be very helpful. The goal is I want to be able to take a WSDL, examine it and create HTTP-SOAP requests for each method in the WSDL and be able to than test them for security issues. The first step is to create those requests!

推荐答案

在调用 SOAP Web 服务时,您可以使用静态调用或动态调用.

When calling a SOAP web service you can use a static invocation or a dynamic invocation.

静态调用意味着从 WSDL 创建一个存根并使用它来执行调用.这会为您创建所有管道"代码,但仅与该 Web 服务紧密相关,您不能将其用于具有不同合同的其他 Web 服务.对于每个 WSDL,您需要创建另一个存根.

Static invocation means creating a stub from the WSDL and using that to perform the call. This creates all the "plumbing" code for you, but is tightly tied to just that web service and you can't use it for other web services with different contracts. For each WSDL you need to create another stub.

通过动态调用,您可以在运行时阅读 WSDL,并根据从 WSDL 获得的信息确定如何调用 Web 服务.向它提供多个 WSDL,客户端就会适应.

With dynamic invocation, you read the WSDL at runtime and figure out how to call the web service based on the info you get from the WSDL. Feed it multiple WSDLs and the client adapts.

动态调用是 SoapUI 用来生成示例请求和响应的内容.

The dynamic invocation is what SoapUI uses to generate the sample requests and responses.

它读取您提供给它的 WSDL,从类型部分提取 XML 模式并生成 XML 实例.为此,它使用 Wsdl4jXmlBeans 幕后.

It reads the WSDL you feed it, extracts the XML schema from the types section and generates XML instances. To do so, it uses Wsdl4j and XmlBeans under the hood.

您决定使用 Wsdl4j 是好的,因为它可以让您在解析 WSDL 时进行控制.但也看看 XmlBeans;它还有一些其他工具,您可能会觉得有用,例如模式到实例 类.

Your decision to use Wsdl4j is good as it gives you control when parsing the WSDL. But also have a look at XmlBeans; it has some other tools you might find useful, like the schema to instance class for example.

如果您需要查看它的运行情况(也许可以调试它以查看发生了什么),您可以使用 SoapUI API 创建一个快速的脏测试:

If you need to see it in action (maybe debug it to see what's going on) you could create a quick dirty test with the SoapUI API:

import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;

public class Test {
    public static void main(String[] args) throws Exception {
        WsdlProject project = new WsdlProject();
        WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?wsdl");
        WsdlInterface wsdl = wsdls[0];
        System.out.println(wsdl.getOperationByName("Add").createRequest(true));
        System.exit(0); // just to clear up some threads created by the project 
    }
}

您应该看到打印的消息(对于 Calculator WS 的 Add 操作)将是这样的:

The message you should see printed (for the Add operation of the Calculator WS) would be something like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Add>
         <tem:a>?</tem:a>
         <tem:b>?</tem:b>
      </tem:Add>
   </soapenv:Body>
</soapenv:Envelope>

希望这能帮助您超越第一步.

Hope this helps you move beyond the first step.

这篇关于将 WSDL 转换为其各自的 HTTP 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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