5

使用 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;
}
4

3 回答 3

5

首先尝试看看你是否得到任何回应。

Object obj = envelope.bodyIn; 

如果这obj不为空,请尝试以下操作。

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;

我的猜测是,如果您得到一些回应,这应该会起作用。

您需要告诉 kSOAPStatusSetting对象是什么how,并将 SOAP 响应转换为StatusSetting对象。

于 2010-06-14T15:27:09.623 回答
1

我希望这对你有帮助:

SoapObject result = (SoapObject) envelope.bodyIn;
String response = result.getProperty(0).toString();
于 2012-02-24T10:03:30.400 回答
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");
    }
}
于 2012-08-15T11:35:55.247 回答