私は Eclipse を使用して Android 上で開発し、.Net Web サービスに接続しようとしています。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();