java调用wsdl的webservice
时间: 2023-08-23 17:08:27 浏览: 145
1. 生成客户端代码
可以使用Java自带的wsimport工具,通过指定WSDL文件的URL生成客户端代码。
命令行方式:
```
wsimport -s <输出目录> <WSDL文件URL>
```
示例:
```
wsimport -s . http://localhost:8080/HelloWorld?wsdl
```
2. 创建服务对象
使用生成的客户端代码中的服务类,创建服务对象。
示例:
```
HelloWorldService service = new HelloWorldService();
HelloWorld port = service.getHelloWorldPort();
```
3. 调用服务方法
使用服务对象调用服务方法。
示例:
```
String result = port.sayHello("World");
System.out.println(result);
```
完整示例:
```
import com.example.helloworld.HelloWorld;
import com.example.helloworld.HelloWorldService;
public class Test {
public static void main(String[] args) {
HelloWorldService service = new HelloWorldService();
HelloWorld port = service.getHelloWorldPort();
String result = port.sayHello("World");
System.out.println(result);
}
}
```
阅读全文
相关推荐
















