简体   繁体   English

Java类从wsdl生成SOAP请求

[英]Java classes to generate SOAP requests from wsdl

I am looking for a way to easily generate SOAP requests from a wsdl file. 我正在寻找一种从wsdl文件轻松生成SOAP请求的方法。 for example, something like this: 例如,如下所示:

WSDLObject myWsdl = new WSDLObject("http://www.whatever.com/myService?wsdl");
SOAPRequest myRequest = myWsdl.generateSOAPRequest();

Is there anything like that? 有没有类似的东西?

I am trying to do it dynamically via another application, so tools like WSDL2Java dont work for me (at least I think). 我正在尝试通过另一个应用程序动态地执行此操作,因此WSDL2Java之类的工具对我不起作用(至少在我看来)。 I need to be able to generate these requests from user input, and then work with them from there. 我需要能够从用户输入生成这些请求,然后从那里处理它们。

any help is appreciated. 任何帮助表示赞赏。

Please see this answer: How to get response from SOAP endpoint? 请参阅以下答案: 如何从SOAP端点获取响应?

What you basically want to do is use the wsimport tool that ships with the JDK. 您基本上想做的是使用JDK附带的wsimport工具。 So long as Java is on your system's classpath, you should be able to go to any terminal or console and do: 只要Java在系统的类路径上,您就应该能够转到任何终端或控制台并执行以下操作:

wsimport http://www.whatever.com/myService?wsdl -p com.company.whateveruwant -d . -keep

With a choice of options ( -d specifies the directory to output the generated code). 选择选项( -d指定用于输出生成的代码的目录)。 This being done, you'll be able to invoke the web service with the auto-generated code quite simply, such as like: 完成此操作后,您将能够非常简单地使用自动生成的代码来调用Web服务,例如:

CustomInterface soap = new CustomEndpoint().getCustomInterface();
System.out.println(soap.getAnswerFromWs("ParamValue"));

You can with WSDL2Java, the unique change is that you work with Java proxy objects and set the attributes of this objects to generate the SOAP request. 您可以使用WSDL2Java,唯一的变化是您可以使用Java代理对象并设置该对象的属性以生成SOAP请求。 Other way is use SOAPUI, for example to generate the SOAP message, and directly construct your SOAP message as StringBuffer and use directly a socket to call the service composing the complete HTTP/SOAP message from scratch. 另一种方法是使用SOAPUI,例如生成SOAP消息,然后将SOAP消息直接构造为StringBuffer,然后直接使用套接字从头开始调用组成完整HTTP / SOAP消息的服务。

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

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