ksoap2 cast getResponse()

时间:2010-06-14 14:44:08

标签: android casting web-services ksoap2

使用kso​​ap2 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;
}

3 个答案:

答案 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");
    }
}