当前位置: 代码迷 >> Web前端 >> apache cxf webservice学习1
  详细解决方案

apache cxf webservice学习1

热度:422   发布时间:2012-07-23 09:42:19.0
apache cxf webservice学习一

第一步下载apache cxf 地址: http://archive.apache.org/dist/cxf/

第二步建立工程项目

第三步导入cxf 所需工程包如下图(我所用的是cxf2.4.2)

?



?创建接口



?实现类



?服务类



?启动服务



?表示启动成功

在ie地址栏输入http://localhost:8080/Webservice/helloWorldService?wsdl

就可以看到自己发布的webservice了

?

调用自己发布的webservice

编写client类

?

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class Client {
??? public static void main(String[] args) {
??? ??? JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
??? ??? factory.getInInterceptors().add(new LoggingInInterceptor());
??? ??? factory.getOutInterceptors().add(new LoggingOutInterceptor());
??? ??? factory.setServiceClass(HelloWorldService.class);
??? ??? factory
??? ??? ??? ??? .setAddress("http://localhost:8080/Webservice/helloWorldService");
??? ??? HelloWorldService client = (HelloWorldService) factory.create();

??? ??? String reply = client.sayHello("gongcheng");
??? ??? System.out.println("Server said: " + reply);
??? }
}

?运行,大功告成。。。。。

(factory.setServiceClass()方法中是接口类名,factory.create()装换的时候也必须是接口名)

?

?

  相关解决方案