Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ksoap2 casting getResponse()

Calling a .net SOAP1.1 web service from android using ksoap2 lib I met a problem of casting response to a custom object. For instance the code below is called correct after httpTransport.call(soapAction, soapEnvelope); and have data inside. But I cant't cast it to specific object neither to SoapObject or Vector as I saw in several examples, I get CastException or simple nothing. If somebody knows how to deal with it, please help.

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;
}
like image 473
Maxim Avatar asked Jun 14 '10 14:06

Maxim


1 Answers

First try and see if you are getting any response.

Object obj = envelope.bodyIn; 

if this obj is not null then try the following.

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;

My guess is this should work if you are getting some response.

You need to tell kSOAP what StatusSetting object is and how to convert a SOAP response to to a StatusSetting object.

like image 176
Soumya Simanta Avatar answered Sep 18 '22 12:09

Soumya Simanta