1. 程式人生 > >Java Axis2釋出及呼叫webservice介面

Java Axis2釋出及呼叫webservice介面

package MZ.GetWebService; 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; public class test { private static String EndPointUrl; private static String QUrl="http://ws.apache.org/axis2"; private QName opAddEntry; private static String WSUrl; public RPCServiceClient setOption() throws AxisFault { RPCServiceClient serviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); EndpointReference targetEPR = new EndpointReference(WSUrl); options.setTo(targetEPR); return serviceClient; } public QName getQname(String Option){ return new QName (QUrl,Option); } // 返回一維String陣列 public String[] getArray(String Option) throws AxisFault { RPCServiceClient serviceClient =this.setOption(); opAddEntry =this.getQname(Option); String[] strArray = (String[]) serviceClient.invokeBlocking(opAddEntry,new Object[]{1,2}, new Class[]{String[].class })[0]; return strArray; } public static void main(String[] argv) throws Exception { RPCServiceClient serviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); EndpointReference targetEPR = new EndpointReference(WSUrl); options.setTo(targetEPR); test ws=new test); ws.WSUrl="http://192.168.2.41:8080/axis2/services/HelloWorld"; String[] hello= ws.getArray("add"); System.out.println(hello[0]); } }


 執行,就可以得到返回的結果了