Lukas
Lukas

Reputation: 405

java.lang.ClassCastException using ksoap2 in android

I'm using Eclipse to develop over android and trying to connect to a .Net webservice. I'm using ksoap2 library to call the webservice but I'm having this exception when calling a method that returns me an arbitrary object:

09-27 16:29:59.641: W/System.err(312): java.lang.ClassCastException: org.ksoap2.serialization.SoapObject

The methods that returns me a boolean or integer works fine, but this keep giving me problems. Here is the response from the server:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<getUsuarioResponse xmlns="http://www.saintek.cl/">
<getUsuarioResult>
<EntityKey>
<EntitySetName>Usuarios</EntitySetName>
<EntityContainerName>ModelNeearsContainer</EntityContainerName>
<EntityKeyValues>
<EntityKeyMember>
<Key>Id</Key>
<Value xsi:type="xsd:int">7</Value>
</EntityKeyMember>
</EntityKeyValues>
</EntityKey>
<Id>7</Id>
<ReputacionId xsi:nil="true" />
<FotoId xsi:nil="true" />
<CoordenadasId xsi:nil="true" />
<FechaNacimiento>1900-01-01T00:00:00</FechaNacimiento>
<FechaRegistro>2012-09-21T16:46:07.707</FechaRegistro>
<Telefono />
<Reputacion_Id xsi:nil="true" />
<Habilitado>false</Habilitado>
<CoordenadaReference />
<FotoReference />
<ReputacionReference />
</getUsuarioResult>
</getUsuarioResponse>
</soap:Body>
</soap:Envelope>

And this is my code:

    String strJson = "";

    String usuario = ((EditText)findViewById(R.id.editText_mail_entrar)).getText().toString();
    String password = ((EditText)findViewById(R.id.editText_password_entrar)).getText().toString();

    request = new SoapObject(WebServiceConstants.NAMESPACE, METHOD_NAME);

    //---le agregamos los parametros---
    request.addProperty("usuario", usuario);
    request.addProperty("password", password);

    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true; //por que es .NET

    envelope.setOutputSoapObject(request);
    //envelope.addMapping(WebServiceConstants.NAMESPACE, "Usuario", new Usuario().getClass());

    HttpTransportSE transporte = new HttpTransportSE(WebServiceConstants.URL);
    transporte.debug = true;

    try {

        transporte.call(SOAP_ACTION, envelope);
        resultsRequestSoap = (SoapPrimitive)envelope.getResponse();

    } catch (IOException e) {

        e.printStackTrace();

    } catch (XmlPullParserException e) {

        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    strJson = resultsRequestSoap.toString();

Upvotes: 1

Views: 768

Answers (1)

Hitesh Jain
Hitesh Jain

Reputation: 408

declare resultsRequestSoap as instace of Object class and try without classcasting as below

 resultsRequestSoap = envelope.getResponse();

Upvotes: 1

Related Questions