java6都出了,我们还要axis和xfire么?

来源:百度文库 编辑:神马文学网 时间:2024/04/30 08:33:02
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发布
代码
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?wsdl
Service端的wsdl
http://localhost:8080/HelloService?wsdl
内容略
Client端的调用
先用wsimport -keep http://localhost:8080/HelloService?wsdl 创建客户端骨干
生成的代码略
自己编写的调用代码
代码
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"));
}
}