• CXF(2.7.10)


    以调用 http://www.webxml.com.cn/ 提供的 IpAddressSearchWebService 服务为例。

    1. 使用 wsdl2java 工具,根据 wsdl 生成 JAX-WS 客户端

    wsdl2java -client "http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl"

    2. 将生成代码导入工程。(可能报错,需要修改)

    3. 访问服务。

    package com.huey.demo.test;
    
    import org.apache.cxf.interceptor.LoggingInInterceptor;
    import org.apache.cxf.interceptor.LoggingOutInterceptor;
    import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
    import org.junit.Test;
    
    import cn.com.webxml.ArrayOfString;
    import cn.com.webxml.IpAddressSearchWebServiceSoap;
    
    public class Wsdl2javaTest {
    
        @Test
        public void testWsdl2java() throws Exception {
            System.out.println("Starting Client...");
    
            JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
            factory.getInInterceptors().add(new LoggingInInterceptor());
            factory.getOutInterceptors().add(new LoggingOutInterceptor());
            factory.setServiceClass(IpAddressSearchWebServiceSoap.class);
            factory.setAddress("http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl");
    
            IpAddressSearchWebServiceSoap ipAddressSearchWebService = (IpAddressSearchWebServiceSoap) factory.create();
            ArrayOfString result = ipAddressSearchWebService.getCountryCityByIp("8.8.8.8");
            for (String str : result.getString()) {
                System.out.println(str);
            }
        }
    
    }
  • 相关阅读:
    Spring一些常用注解及其作用
    Spring、Springboot、Springcloud的区别
    JVM常见配置
    Statement对象
    运算符优先级
    Java中的关键字有哪些?
    Servlet生命周期
    String类型的认识以及编译器优化
    JSTL--简单标签
    JSTL--表达式操作
  • 原文地址:https://www.cnblogs.com/huey/p/4589090.html
Copyright © 2020-2023  润新知