Service的設計
代碼
- package org.hermit.study.jdk;
-
- import javax.jws.WebMethod;
- import javax.jws.WebService;
- import javax.jws.soap.SOAPBinding;
-
- @WebService(targetNamespace = "http://jdk.study.hermit.org/client")
- @SOAPBinding(style = SOAPBinding.Style.RPC)
- public class Hello {
- @WebMethod
- public String sayHello(String name) {
- return "hello:" + name;
- }
- }
Service發(fā)布
代碼
- package org.hermit.study.jdk;
- import javax.xml.ws.Endpoint;
-
- public class StartService ...{
- public static void main(String[] args) ...{
- Endpoint.publish("http://localhost:8080/HelloService", new Hello());
- }
- }
http://localhost:8080/HelloService?wsdlService端的wsdl
http://localhost:8080/HelloService?wsdl
內(nèi)容略
Client端的調(diào)用
先用wsimport -keep http://localhost:8080/HelloService?wsdl 創(chuàng)建客戶端骨干
生成的代碼略
自己編寫的調(diào)用代碼
代碼
- package org.hermit.study.jdk.client.test;
-
- import org.hermit.study.jdk.client.Hello;
- import org.hermit.study.jdk.client.HelloService;
-
- public class TestClient {
- public static void main(String[] args) {
- HelloService service = new HelloService();
- Hello _hello = service.getHelloPort();
- System.out.println(_hello.sayHello("hermit"));
- }
- }