通過生成客戶端的方式調用
整體流程
- 先準備Axis的相關文件(axis2-1.7.9-bin.zip)
- cmd到axis2/bin的目錄下(啓動axis2server.bat,用於測試)
- 執行(wsdl2java命令) wsdl2java -uri "http://localhost:8080/axis2/services/Version?wsdl" -p version -o D:\version\java
- 新建一個maven項目,添加axis2的相關依賴jar包,將生成的java文件拷進去
- 編寫客戶端代碼,測試
參考示例
axis2的相關依賴jar包
<!-- webservice 遠程調用接口 -->
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-spring</artifactId>
<version>1.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.7.9</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.7.9</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>addressing</artifactId>
<version>1.7.9</version>
</dependency>
測試類
package version;
import org.apache.axis2.AxisFault;
import java.rmi.RemoteException;
public class VersionTest {
public static void main(String[] args) {
try {
VersionStub vs = new VersionStub();
VersionStub.GetVersion request = new VersionStub.GetVersion();
VersionStub.GetVersionResponse response = vs.getVersion(request);
String version = response.get_return();
System.out.println(version);
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
} catch (VersionExceptionException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
返回結果