hena12
hena12

Reputation: 63

java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject

SoapObject request = new SoapObject(NAMESPACE, "api_vps_get_service");
// Property which holds input parameters
PropertyInfo unamePI = new PropertyInfo();

// Set token
unamePI.setName("token");
// Set Value
unamePI.setValue(token);
// Set dataType
unamePI.setType(String.class);
// Add the property to request object
request.addProperty(unamePI);

// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
 envelope.dotNet=true;
 envelope.setOutputSoapObject(request);
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {

    // Invoke web service
    androidHttpTransport.call(SOAP_ACTION+"api_vps_get_service", envelope);
    // Get the response

    SoapObject response=(SoapObject)envelope.bodyIn;


    String reponses = response.toString();
    Log.i("reponse", String.valueOf(reponses));

} catch (Exception e) {
    //Assign Error Status true in static variable 'errored'
    Home.errored = true;
    e.printStackTrace();
}

i am getting this error java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject i tried SoapPrimitive response = (SoapPrimitive) envelope.getResponse(); and also Object response = (Object) envelope.getResponse(); but no success anyone please tell me why i my getting error?

Upvotes: 0

Views: 7050

Answers (1)

mmprog
mmprog

Reputation: 781

Server returned error. So there is no SoapObject nor SoapPrimitive. You have to check first for SoapFoult like that:

if (envelope.bodyIn instanceof SoapFault)
{
    final SoapFault sf = (SoapFault) envelope.bodyIn;
    ... // Stuff
}

this is described here: https://code.google.com/p/ksoap2-android/issues/detail?id=177

Upvotes: 1

Related Questions