1

我正在使用 Eclipse 通过 android 进行开发并尝试连接到 .Net 网络服务。我正在使用 ksoap2 库来调用 web 服务,但在调用返回任意对象的方法时出现此异常:

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

返回布尔值或整数的方法可以正常工作,但这一直给我带来问题。这是来自服务器的响应:

<?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>

这是我的代码:

    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();
4

1 回答 1

1

将 resultsRequestSoap 声明为 Object 类的实例,并尝试不进行类转换,如下所示

 resultsRequestSoap = envelope.getResponse();
于 2012-09-27T16:10:03.453 回答