- 开发环境:eclipse 、jdk
- 创建服务端 demo-webservice
- 创建类 HelloService.java
package com.hundsun.ws.service;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class HelloService {
public String getResult(){
return "OK";
}
public static void main(String[] args){
Endpoint.publish("http://127.0.0.1:8080/helloService", new HelloService());
}
}
- 创建客户端demo-client
- cmd wsimport -s D:\soft\workspace\fem-shop-1.3\demo-client\src -p com.hundsun.ws.client -keep http://localhost:8080/helloService?wsdl
- refresh demo-client
- 新建测试类 Test.java
-
package com.hundsun.ws.test;
import com.hundsun.ws.client.HelloService;
import com.hundsun.ws.client.HelloServiceService;
public class Test {
public static void main(String[] args) {
HelloService hs = new HelloServiceService().getHelloServicePort();
System.out.println(hs.getResult());
}
}