`

java生成webservice客户端

 
阅读更多

准备工作:

1、下载apache-cxf-3.2.7包,点击进入官网下载地址

2、配置环境变量:在环境变量中配置,CXF_HOME 值为apache-cxf-3.2.7地址。例如我的地址为D:\install\cxf\apache-cxf-3.2.7;在PATH中加入%CXF_HOME%\bin。

好了,进入正题:

1、首先,我们需要知道对接系统接口地址,用浏览器打开接口地址。

2、将页面内容另存为.wsdl文件。

3、打开cmd命令行,进入apache-cxf-3.2.7的bin目录下

4、执行命令:wsdl2java -p com -d xxxx -client xxxxx.wsdl,执行完毕后,会在目标位置生成webservice的客户端代码。

5、我们可以参考client类书写客户端调用代码。

参数解释:

(1)-p  指定其wsdl的命名空间,也就是要生成代码的包名;

(2)-d  指定要产生代码所在目录 ;

(3)-client 生成客户端测试web service的代码 ;

(4)-server 生成服务器启动web  service的代码 。

 

解决CXF的msdl2java生成的继承service类的构造函数报错问题

这是三个报错的构造函数:
    //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
        //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
        //compliant code instead.
        public IcpBusinessService(WebServiceFeature ... features) {
            super(WSDL_LOCATION, SERVICE, features);
        }
    
        //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
        //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
        //compliant code instead.
        public IcpBusinessService(URL wsdlLocation, WebServiceFeature ... features) {
            super(wsdlLocation, SERVICE, features);
        }
    
        //This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2
        //API jar or re-run wsdl2java with "-frontend jaxws21" to generate JAX-WS 2.1
        //compliant code instead.
        public IcpBusinessService(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
            super(wsdlLocation, serviceName, features);
        }


 原因请参考:http://cxf.apache.org/docs/23-migration-guide.html   官方说明。

 其不能正常编译通过是由于jax-ws2.2规约与java6冲突。 但程序又不能仅以java5来编译,故需要降低jax-ws规约版本,

可以这样处理:  执行命令

wsdl2java -frontend jaxws21 -d xxxx -client xxxxx.wsdl

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics