Eclipse Maven生成WebService客户端代码及测试
时间:2016-06-30 14:46:49
收藏:0
阅读:4213
条件:
1. Eclipse安装Axis2插件
2. 导入Web Service相关包
创建Maven项目
导入axis2相关jar包
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.soap</groupId> <artifactId>soap</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>soap-client</artifactId> <dependencies> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>1.7.1</version> </dependency> </dependencies> </project>
wsdl详情
生成Web Service客户端代码:
即生成客户端代码
生成客户端代码测试案例:
package com.soap.client; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import org.apache.axis.AxisFault; import cn.com.tech_trans.www.CRM_VIP_ProxyLocator; import cn.com.tech_trans.www.CRM_VIP_ProxySoapStub; import cn.com.tech_trans.www.ResponseDataOfBasicInfo; /** * 客户端测试代码 * @author Roger */ public class ClientTestGetBasicInfo { public static void main(String[] args) throws Exception { try { // 服务端Service CRM_VIP_ProxyLocator service = new CRM_VIP_ProxyLocator(); // 服务端web service 的wsdl地址 URL endpointURL = new URL("http://-------:1999/CRM_VIP_Proxy.asmx?WSDL"); // 通过wsdl地址与service获取Proxy CRM_VIP_ProxySoapStub stub = new CRM_VIP_ProxySoapStub(endpointURL, service); // 调用接口 ResponseDataOfBasicInfo basicInfo = stub.getBasicInfo(); // 响应信息 System.out.println(basicInfo); } catch (AxisFault e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } } }
当需要调用其他接口,只需要将相应的调用接口换掉就可以
测试结果
六月 30, 2016 11:05:26 上午 org.apache.axis.utils.JavaUtils isAttachmentSupported 警告: Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled. cn.com.tech_trans.www.ResponseDataOfBasicInfo@739feed3
评论(0)