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()装换的时候也必须是接口名)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值