67,516
社区成员
发帖
与我相关
我的任务
分享
package com.axis2.test;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import com.axis2.entity.MyBank;
/**
* 调用axis2的webservice
* */
public class TestAxis2 {
private static TestAxis2 bean = new TestAxis2();
private String serviceUrl = "http://localhost:8088/bank/services/bankService";// webservice的url
private String nameSpace = "http://service.bank.com";// webservice的命名空间(其实就是协议和包名的倒写)
/**
* @see 调用axis2的webservice
* @param method 发布方的方法名
* @param args 方法中的参数列表
* @return MyBank
* */
@SuppressWarnings("unchecked")
public MyBank useAxis2(String method, Object[] args) {
MyBank bank = null;
RPCServiceClient client=null;
try {
client = new RPCServiceClient();
Options option = client.getOptions();
EndpointReference erf = new EndpointReference(serviceUrl);
option.setTo(erf);
QName name = new QName(nameSpace, method);
Class[] returnTypes = new Class[] { MyBank.class };
Object[] response = client.invokeBlocking(name, args, returnTypes);
bank = (MyBank) response[0];
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
client.cleanupTransport();
} catch (AxisFault e) {
e.printStackTrace();
}
}
return bank;
}
public static void main(String[] args) {
MyBank fromBack = new MyBank();
MyBank toBank = new MyBank();
MyBank bank = bean.useAxis2("transition", new Object[]{ fromBack, toBank });
System.out.println(bank.getPrompt());
}
}