[英]Ksoap on android— get a list response from a java web service
I have a java web service (soap) which i want to use with an android client for that am using ksoap. 我有一个java web服务(肥皂),我想使用Android客户端,因为我正在使用ksoap。
My web service gives an answer which look like this : 我的网络服务提供了如下答案:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:listealbumResponse xmlns:ns2="http://ws/">
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:album">
<annee>2008</annee>
<id>6</id>
<titre>Ninja Tuna</titre>
</return>
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:album">
<annee>2008</annee>
<id>10</id>
<titre>Fine Music, Vol. 1</titre>
</return>
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:album">
<annee>2004</annee>
<id>14</id>
<titre>Bob Acri</titre>
</return>
<return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:album">
<annee>2009</annee>
<id>54</id>
<titre>Rated R</titre>
</return>
</ns2:listealbumResponse>
</S:Body>
</S:Envelope>
wich is a list of object 这是一个对象列表
To call my web service i use this code : 要调用我的Web服务,我使用以下代码:
try{
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(Request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject)envelope.getResponse();
When i tested my response "result" it's got only one object , how could i get all the list and parse it? 当我测试我的响应“结果”时,它只有一个对象,我怎么能得到所有列表并解析它?
The problem was that when i parse the soap response i got only the first object of the list so i changer this line : 问题是,当我解析soap响应时,我只获得了列表的第一个对象,所以我改变了这一行:
SoapObject result = (SoapObject)envelope.getResponse();
with : 用:
SoapObject result = (SoapObject)envelope.bodyIn;
wiht that i got all the list and i add this 我得到了所有的清单,我加上这个
testValues = new String[result.getPropertyCount()];
for(int i= 0; i< result.getPropertyCount(); i++){
testValues[i] = result.getProperty(i).toString();
}
Good luck and thank you Janusz 祝你好运,谢谢Janusz
Code: 码:
SoapObject result = (SoapObject)envelope.bodyIn;
String output = "";
for(int i= 0; i< result.getPropertyCount(); i++){
SoapObject object = (SoapObject)response.getProperty(i);
output += "annee : " + object.getProperty("annee") + "\n";
output += "id : " + object.getProperty("id") + "\n";
output += "titre : " + object.getProperty("titre") + "\n";
}
The result is a single SoapObject this objects however should have a property for every item in the list that you requested. 结果是单个SoapObject,但是这个对象应该具有您请求的列表中每个项目的属性。 You could do something like this to retrieve all the items: 您可以执行以下操作来检索所有项目:
private static List parseLists(List listItems, SoapObject response) {
int propertyCount = response.getPropertyCount();
for (int currentProperty = 0; currentProperty < propertyCount; currentProperty++) {
Object input = response.getProperty(currentProperty);
Object result = parseObject(input.toString());
if (result != null) {
listItems.add(result);
}
}
return listItems;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.