80,362
社区成员
发帖
与我相关
我的任务
分享
List<Building>getBuildingsByAccountName(String accountName);
String method = "getBuildingsByAccountName";//方法名称
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("accountName", String.valueOf("max")));
retrurn WSHelper.GetResponse(method,params);
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;
}
}
}