您的位置:首页 > 其它

CXF之使用jaxws API 发布服务与进行客户端调用

2010-07-31 17:27 901 查看
使用jaxws API 发布服务:

]package server;
import javax.xml.ws.Endpoint;
public class Server {
protected Server() throws Exception {

System.out.println("Starting Server");
MyHelloWorldImpl implementor = new MyHelloWorldImpl();
String address = "http://localhost:9000/myHelloWorld";
Endpoint.publish(address, implementor);
}
public static void main(String args[]) throws Exception {

new Server();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
}


使用jaxws API处理客户端调用:

]package client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import server.MyHelloWorld;
/**
* 第二种访问方式
* @author FHD
*/
public class Client2 {

public static void main(String[] args) {
URL wsdlURL = null;
try {
wsdlURL = new URL("http://localhost:9000/myHelloWorld?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
}

final QName SERVICE_NAME = new QName("http://server/", "FHDHelloWorld");
Service service = Service.create(wsdlURL, SERVICE_NAME);

MyHelloWorld hw = service.getPort(MyHelloWorld.class);
hw.sayHi("fuhaidong");
System.out.println("client: fuhaidong");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐