axis2 的客户端怎么样获取 服务端查询出来的list集合啊?有没有什么办法可以实现。。或者其他的办法实现求教啊

解决方案 »

  1.   

    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());
    }

    }
      

  2.   

    上面的代码接收的是一个实体类,List也是一样的,你强制转换一下就可以了,
    如果list要泛型的话,你就先判断一下返回的class再转,否则可能会引发类型转换异常
    System.out.print(response[0].getClass().getName());