[原创]webservice 学习笔记,axis2 传递对象数组,非stub方式
还是用 我博客《webservice 学习笔记,axis2传输简单对象,非stub方式
》的例子:
首先建立ServiceTest.java
package sample.ws.client;import javax.xml.namespace.QName;import org.apache.axis2.addressing.EndpointReference;import org.apache.axis2.client.Options;import org.apache.axis2.rpc.client.RPCServiceClient;import sample.ws.pojo.Person;public class Ws2pojoClient {public static void main(String args[]) throws java.lang.Exception {RPCServiceClient client = new RPCServiceClient();Options option = client.getOptions();// 指定客户端访问的webservice服务器端地址EndpointReference erf = new EndpointReference("http://localhost:9999/Ws2Pojo/services/TestService");option.setTo(erf);// 指定命名空间,指定要调用的方法QName name = new QName("http://service.ws.sample", "getPerson");// 创建Person对象Person person1 = new Person();person1.setAge("20");person1.setName("张三");Person person2 = new Person();person2.setAge("30");person2.setName("李四");// 创建Person数组Person[] person3 = new Person[2];person3[0] = person1;person3[1] = person2;// 创建要传送的object数组Object[] object = new Object[] { person3 };// 创建返回的参数类型Class[] returnTypes = new Class[] { Person[].class };// 调用远程服务,得到返回的object数组Object[] response = client.invokeBlocking(name, object, returnTypes);// 强制转换成Person[]对象Person[] p = (Person[]) response[0];// 遍历得到我们刚刚请求过去的值for (int i = 0; i < p.length; i++) {System.out.println(p[i].getAge());System.out.println(p[i].getName());}}}