server端:
服务:
@WebService(targetNamespace="")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class TestServer {
public TestServer(){
System.out.println("register");
}
@WebMethod(action="toSayHello",operationName="toSayHello",exclude=false)
@WebResult(name="returnWord")//自定义该方法返回值在WSDL中相关的描述
public String sayHello(@WebParam(name="userName")String userName) {
System.out.println( "Hello:" + userName);
return "Hello:" + userName;
}
}
启动服务:
public class StartServer {
public static void main(String[] args) {
Endpoint.publish("http://localhost/webservice/", new TestServer());
}
}
可以访问http://localhost/webservice/?wsdl
client端
通过反编译
命令:
wsimport -s 需要生成JAVA类所在的文件夹路径 -keep http://localhost/webservice/?wsdl
拿到
TestServer.java和TestServerService.java
!!!!!注意:运行的时候服务要开着!!!!!
public class TestClient {
public static void main(String[] args) {
TestServerService test = new TestServerService();
System.out.println( test.getTestServerPort().toSayHello("sunhao") );//调用WEBSERVICE的sayHello方法
}
}