其实就是一个WebService返回结果怎么转换成List<T>的问题,我是一直搞C#的,Java不熟
下面是代码 WebService方法原型   List<Building>getBuildingsByAccountName(String accountName);
Java代码调用如下:
        String method = "getBuildingsByAccountName";//方法名称
            List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
            params.add(new BasicNameValuePair("accountName", String.valueOf("max")));        retrurn WSHelper.GetResponse(method,params);
下面是WSHelper类
public class WSHelper {
        final static String WSUrl="http://192.168.5.25:8080/automation/services/equipService?wsdl";
         
    private static String namespace = "http://webservice.device.automation.zhaohai.com/";
    /*************************************
     * 获取web services内容
     * @param url
     * @param params
     * @return
     *************************************/
    @SuppressWarnings("deprecation")
        public static List<Building> GetResponse(String method,List<BasicNameValuePair> params)
    {
        try 
        {
            String url = WSUrl;
            SoapObject request = new SoapObject(namespace, method);
            for(int i=0,len=params.size();i<len;i++){
                request.addProperty(params.get(i).getName(), params.get(i).getValue());
            }
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
            envelope.bodyOut = request;
            HttpTransportSE ht = new HttpTransportSE(url);
            ht.call(null, envelope);
            String result="";
            List<Building> list;
            if(envelope.getResponse() != null)
            {
                    SoapObject soapObject = (SoapObject) envelope.getResponse(); 
                    //List<Building> list = envelope. //这里不知道怎么写了
                    //List<Building> list=soapObject.getClass();//这样写是错的
                // 通过getProperty下面这种方法可以得到类中属性的值 ,但要重新实例化一个Building,就太耗资源了,
                    //所有肯定有直接获得List的方法
                result += "building名称:" + soapObject.getProperty("name") + "\n";  
                result += "ID:" + soapObject.getProperty("pid") + "\n";  
            }  
            else result="no value";
            return list;
        } catch (Exception e) {
            return null;
        }
    }
}

解决方案 »

  1.   

    谢谢Java高手,android高手,WebService高手帮忙,感激不尽啊
      

  2.   


    List<Building> list = envelope. //这里不知道怎么写了
    我的感觉 是通过envelope对象可以得到,但是不知道怎么写
      

  3.   

    调试看了envelope对象的所有值 ,貌似只有Bodyin属性有我要的值 ,,
    转不了实体类
    Bodyin的数据结构是这样的
    getBuildingsByAccountNameResponse{return=anyType{pid=1; pid=1; name=building1; }; return=anyType{pid=2; pid=2; name=building2; }; }
    我要的是anyType大括号抱住的两段,实体类中三个属性,也就是两条数据
      

  4.   

    给你个思路,你可以这样,分两部走:
    1.String result=object.toString()
    2.result作为一个String类型的xml文件流 ,然后再使用SAX读取这个xml文件 ,你主要要做的是如何用SAX去解析、操作。
      

  5.   

    用SAX去解析,参考下:http://www.cnblogs.com/feisky/archive/2011/01/10/1932164.html
      

  6.   

    可以说是没解决。。
    那个东西,貌似没有包可以得到List<T>
    后来我们用HTTP协议了
      

  7.   

    貌似无法直接解析List集合,只能解析向量集合Vector。
    Server:  Vector<T> vec = new Vector();  
             vec.addAll(     List<T>    );
    Android: Vector<SoapObject> vec = (Vector<SoapObject>) envelope..getResponse(); 这句容易出类转换异常,我也不知道哪的问题,别人运行的没问题--! 
             for (SoapObject list : vec) { 
                list.getProperty(       );
             }