使用ksoap2 lib从android调用.net SOAP1.1 Web服务我遇到了对自定义对象进行响应的问题。例如,在httpTransport.call(soapAction,soapEnvelope)之后调用下面的代码是正确的。并在里面有数据。但我不能把它转移到SoapObject或Vector的特定对象,就像我在几个例子中看到的那样,我得到CastException或者什么都不简单。 如果有人知道如何处理它,请帮助。
public StatusSetting[] GetAllStatuses(String installation){
StatusSetting[] statuses = null;
String methodName = "GetAllStatuses";
String soapAction = NAMESPACE + "/" + methodName;
SoapObject request = new SoapObject(NAMESPACE, methodName);
request.addProperty("installation", installation);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(SERVICE_URL);
try {
httpTransport.call(soapAction, soapEnvelope);
statuses = (StatusSetting[])soapEnvelope.getResponse();
} catch (Exception e) {
e.printStackTrace();
}
return statuses;
}
答案 0 :(得分:5)
首先尝试看看您是否收到任何回复。
Object obj = envelope.bodyIn;
如果此obj
不为null,请尝试以下操作。
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
我的猜测是,如果您得到一些回复,这应该可行。
您需要告诉kSOAP将StatusSetting
对象和how
转换为StatusSetting
对象。
答案 1 :(得分:1)
我希望这会对你有所帮助:
SoapObject result = (SoapObject) envelope.bodyIn;
String response = result.getProperty(0).toString();
答案 2 :(得分:0)
类似的东西:
SoapObject response = (SoapObject) envelope.getResponse();
yourArray=new String[response.getPropertyCount()];
for(int i=0;i<response.getPropertyCount();i++){
Object property = response.getProperty(i);
if(property instanceof SoapObject){
SoapObject final_object = (SoapObject) property;
yourArray[i] = final_object.getProperty("YOUR_PROPERTY_NAME");
}
}