到apache 下载cxf需要的包,最好jdk6.0免得出错
public class WebserviceServer {
public WebserviceServer(){
HelloServiceImpl hello = new HelloServiceImpl();
ServerFactoryBean factory = new ServerFactoryBean();
factory.setServiceClass(IHelloService.class);
factory.setAddress("http://127.0.0.1:9000/Hello");
factory.setServiceBean(hello);
factory.create();
}
public static void main(String[] args) throws InterruptedException {
new WebserviceServer();
System.out.println("server starting......");
Thread.sleep(60*1000);
System.out.println("server exit");
System.exit(0);
}
启动server
浏览器查看:
http://127.0.0.1:9000/Hello?WSDL
调用webservice
public class Client {
public static void main(String[] args) {
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(IHelloService.class);
factory.setAddress("http://127.0.0.1:9000/Hello");
IHelloService hello = (IHelloService) factory.create();
System.out.println(hello.sayHello("hello lmning"));
}
}
ok!