cxf客户端

按下面步骤逐步搭建cxf客户端代码:

1、下载cxf
2、在bin目录下生成客户端存根:wsdl2java -encoding utf-8 http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
3、主要是使用上面存根的接口类,单做本地代码来使用,
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setServiceClass(IpAddressSearchWebServiceSoap.class);//设置请求接口
         factory.setAddress("http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl");
         IpAddressSearchWebServiceSoap esbServer = (IpAddressSearchWebServiceSoap) factory.create(); //创建客户端对象

         //设置客户端的配置信息,超时等.
         Client proxy = ClientProxy.getClient(esbServer);
         HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
         HTTPClientPolicy policy = new HTTPClientPolicy();
         policy.setConnectionTimeout(10000); //连接超时时间
         policy.setReceiveTimeout(12000);//请求超时时间.
         conduit.setClient(policy);
         System.out.println("测试:" + esbServer.getCountryCityByIp("119.23.204.XX").getString()); //调用方法。

4、在springboot中引入cxf相关类;
            <!-- CXF webservice -->
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
                <version>3.1.11</version>
            </dependency>

补充:
cxf默认30秒超时
用命令生成的存根,其实


另外一种写法如下,不过没弄清楚超时时间加在哪里合适
//        System.out.println(new IpAddressSearchWebService().getIpAddressSearchWebServiceSoap().getCountryCityByIp("119.23.204.XX").getString());
//        System.out.println("2222222222222222222222222222");

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值