[英]How to create a Java client for Web Service?
I have successfully created Web Service .
我已成功创建Web服务 。 Tested it and getting the WSDL file also.
测试它并获取WSDL文件。 The client that will use this Web Service is a simple Java class.
将使用此Web Service的客户端是一个简单的Java类。
I am able to create a jsp client and call the methods of Web Service. 我能够创建一个jsp客户端并调用Web Service的方法。 But I need to call the Web Service from a Java class.
但我需要从Java类调用Web服务。
How do I bind this Java client with Web Service? 如何将此Java客户端与Web Service 绑定 ?
The following steps I followed in NetBeans for creating the Java Client... 我在NetBeans中执行以下步骤来创建Java客户端...
But I'm not able to call the method of the WebService. 但是我无法调用WebService的方法。 Here is the Client file...
这是客户端文件......
package client_package;
public class client {
public static void main(String args[])
{
System.out.println("1");
System.out.println(hello("megha"));
System.out.println("2");
}
private static String hello(String name) {
WS_package.WebService1 service = new WS_package.WebService1(); //package WS_package does not exists
WS_package.WebService1 port = service.getWebService1Port(); //package WS_package does not exists
name = port.hello(name);
return name;
}
}
You could use wsimport tool to generate a client stub files, from command line: 您可以使用wsimport工具从命令行生成客户端存根文件:
wsimport -keep http://localhost:8080/webservices/helloService?wsdl
then import the generated files and use them like you did above 然后导入生成的文件并像上面一样使用它们
HelloServiceImplService helloService = new HelloServiceImplService();
HelloService hello = helloService.getHelloServiceImplPort();
There are also some frameworks arround to work with Webservices, like Apache CXF and Apache Axis 还有一些与Web服务一起使用的框架,如Apache CXF和Apache Axis
Update: Just noticed its an old question, if the OP knew the answer, he should update the topic. 更新:刚刚注意到一个老问题,如果OP知道答案,他应该更新主题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.