條件:java
1. Eclipse安裝Axis2插件
web
2. 導入Web Service相關包
apache
建立Maven項目dom
導入axis2相關jar包maven
<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詳情ide
生成Web Service客戶端代碼:測試
即生成客戶端代碼
ui
生成客戶端代碼測試案例:.net
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