[英]Create a SOAP Webservice Client Application in Java
I have created in eclipse a Webservice in Java using Apache CXF , now I have to create a WebService client application to consume and invoke it.我在 Eclipse 中使用Apache CXF在 Java 中创建了一个 Webservice,现在我必须创建一个 WebService 客户端应用程序来使用和调用它。 I have been searching a way to do it, and I found that Client is always dependent to the server's Java Class.
我一直在寻找一种方法来做到这一点,我发现客户端总是依赖于服务器的 Java 类。
The problem is that I have to develop a client class in an other Java environment.问题是我必须在其他 Java 环境中开发一个客户端类。 My question is : Is there a way to develop a client class which will be independent of webservice server's package, using only the WSDL file ?
我的问题是:有没有办法开发一个独立于 web 服务服务器包的客户端类,只使用WSDL文件?
Thank you :)谢谢 :)
You can take help of Apache CXF
Link wsdl to java tool.您可以借助
Apache CXF
Link wsdl to java 工具。 wsdl2java
- takes a WSDL document and generates fully annotated Java code from which to implement a service. wsdl2java
- 获取一个 WSDL 文档并生成完全注释的 Java 代码,从中实现服务。
You can take help of eclipse plugin also.您也可以借助 eclipse 插件。
You can send request to web service API as XML request.您可以将请求作为 XML 请求发送到 Web 服务 API。 Only thing you would need to constuct SOAP complaint request with proper header and body.
只有您需要使用正确的标题和正文来构造 SOAP 投诉请求。 By using SoapUI you can generate the XML request structure, and then reuse it in your application.
通过使用 SoapUI,您可以生成 XML 请求结构,然后在您的应用程序中重用它。
If you are using Jax-RS(REST APIs), even http method also works如果你使用 Jax-RS(REST APIs),即使是 http 方法也可以
[update] [更新]
If you are stuck with how to create client classes, then you would follow this如果您对如何创建客户端类感到困惑,那么您将遵循此
Use wsimport使用 wsimport
> http : //hostname :port/wsdl.url on command line to create proxy classes
Create jar file generated proxy classes创建jar文件生成代理类
Sample test client is given below.下面给出了示例测试客户端。
try { URL wsdlURL = new URL("http://localhost:8082/cxf/services/yourservice?wsdl"); QName SERVICE_NAME = new QName("http://package.name/","PORTNAme"); Service service = Service.create(wsdlURL, SERVICE_NAME); client = service.getPort(PORTInterface.class); client.executeYourMethod() } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
Cheers Satheesh干杯萨西什
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.