一、背景介绍:
a、有时遇到复杂的webservice接口,如直接访问的webservice通过<import>引用其他webservice且被引用页和引用页namespace不相同时,
JDK反编译webservice客户端就会报错。
二、问题分析:
a、用soapUI导出客户端需要axis2-1.4.1这个jar来支持,该包可以在云盘公用软件中找到。
b、使用soapUI导出客户端代码等同与wsdl2java-p com -d src -uri aa.wsdl而且后者往往更有效,参数项可省略。这个需要上述压缩包中的axis2-1.4.1-bin中的bin目录下在命令行执行。
-p 指定其wsdl的命名空间,也就是要生成代码的包名:
-d 指定要产生代码所在目录
-client 生成客户端测试web service的代码
-server 生成服务器启动web service的代码
-impl 生成web service的实现代码
-ant 生成build.xml文件
-all 生成所有开始端点代码:types,service proxy,,serviceinterface, server mainline, client mainline,
三、具体实现
操作步骤(使用的jar是axis2-1.4.1-bin/axis2-1.4.1)
- 启动soapUI工具,效果如下图:
- 选择菜单栏中的“Tools” -> “Axis2 Artifacts”选项:
- 在“Axis2 Artifacts”界面,点击“Tools”按钮:
- 配置axis2解压后的路径地址,完成后点击“Ok”按钮确定:
- 参照如下截图,配置WSDL文件路径和代码输出路径:
- 完成如上设置后,点击“Generate”按钮,即可生成客户端代码,生成过程如下图:
四、程序运行需要的JAR
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.5.1</version>
<type>pom</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.5.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.5.1</version>
<type>jar</type>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>org.apache.ws.commons.schema</artifactId>
<groupId>XmlSchema</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>3.0.3</version>
</dependency>