cxf调用客户端的方法
1 进入到 cxf资源 bin目录
--->cmd --> cd C:/Documents and Settings/Administrator/桌面/apache-cxf-2.2.7/apache-cxf-2.2.7/bin
--->wsdl2java -p com.service -d d://aa http://localhost:8080/loginService
在d://aa下生成一个该地址下的客户端 将d://aa下的文件夹拷贝到项目中即可使用
2 如果在myeclipse 就更简单了
新建一个web工程 新建一个 webservice客户端 选择 jax-ws
输入你的webservice地址 记得要加 ?wsdl否则不能验证通过
会生成跟1部一样的客户端
3你也可以自己写客户端调用
1》如果是 前面通过工具生成的客户端
UserServiceImplService serivce = new UserServiceImplService();
UserServiceImpl impl = serivce.getUserServiceImplPort();
User u = new User();
impl.addUser(u);
2》不通过工具类生成 第一种
System
.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory",
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("http://localhost:8088/abc");
QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
factory.setServiceName(SERVICE);
factory.setServiceClass(UserService.class);
UserService us = (UserService) factory.create();
User u = new User();
// us.addUser(u);
us.addUser(u);
3》不通过工具类生成 第二种
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(UserService.class);
factory.setAddress("http://localhost:8088/abc");
// factory.getServiceFactory().setDataBinding(new AegisDatabinding());
UserService client = (UserService) factory.create();
User u = new User();
client.addUser(u);
4》是第一种的底层实现
QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
QName UserServiceImplPort = new QName("http://liaomin", "UserServiceImplPort");
URL url = new URL("http://localhost:8088/abc?wsdl");
ServiceDelegate dele=Provider.provider().createServiceDelegate(url,SERVICE,Service.class);
UserService us = (UserService) dele.getPort(UserServiceImplPort,UserService.class);
User u = new User();
us.addUser(u);