Android Ksoap2包调用WebService怎么得到List对象
其实就是一个WebService返回结果怎么转换成List<T>的问题,我是一直搞C#的,Java不熟
下面是代码
WebService方法原型
Java代码调用如下:
下面是WSHelper类
下面是代码
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;
}
}
}
...全文
相关推荐
Android之Webservice详解与调用天气预报Webservice完整实例
Android之Webservice详解与调用天气预报Webservice完整实例
Android使用ksoap2库调用Webservice实战
ksoap2是一个开源的Java库,专门用于Android平台的SOAP Web服务调用。其名称来源于”SOAP with a Java Object”的概念。该库最初由Dave Cramer于2001年创立,旨在简化通过SOAP协议进行远程过程调用(RPC)的过程。它通过封装SOAP消息的创建和解析过程,为开发者提供了一种快捷简便的方式来与Web服务交互。ksoap2的主要功能包括:- 封装了SOAP消息的构建和解析逻辑,使开发者可以专注于业务逻辑处理,而不是底层的SOAP细节。
Android调用Webservice使用的ksoap2包
Android通过Ksoap包的方法 调用了 .net webserivce
在Android 中使用KSOAP2调用WebService
在Android 中使用KSOAP2调用WebService.docx
在android中使用KSOAP2调用webservice
简述在android中使用ksoap2调用webservice的方法


