Cast on a SoapObject

1

I have the following code to consume WebService :

  public List<Convenio_Conselho_Grid_BD> Pesquisar_Convenios(int pCodigo_Entidade) {

    SoapObject request = new SoapObject(oFinanceiro.WSDL_TARGET_NAMESPACE, oFinanceiro.OPERATION_NAME);
    PropertyInfo pi = new PropertyInfo();
    pi.setName("pCodigo_Entidade");
    pi.setValue(pCodigo_Entidade);
    pi.setType(Integer.class);
    request.addProperty(pi);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE httpTransport = new HttpTransportSE(oFinanceiro.SOAP_ADDRESS);

    Object response = null;
    try {
        envelope.addMapping(oFinanceiro.WSDL_TARGET_NAMESPACE, "Convênio Conselho", Convenio_Conselho_Grid_BD.class);
        httpTransport.call(oFinanceiro.SOAP_ACTION, envelope);
        response = envelope.getResponse();


    } catch (Exception exception) {
        Log.d("Erro", exception.toString());
    }
    return (List<Convenio_Conselho_Grid_BD>) response;
}

But when it returns the object, it gives the following error:

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

I have tried to do several types of cast and nothing works. This type was created in the project in .net and I created the same type with the same properties in the project android

    
asked by anonymous 02.05.2018 / 22:10

1 answer

0

The solution was to change the return type of the method to SoapObject

    public SoapObject Pesquisar_Convenios(int pCodigo_Entidade) {

    SoapObject request = new SoapObject(oFinanceiro.WSDL_TARGET_NAMESPACE, oFinanceiro.OPERATION_NAME);
    PropertyInfo pi = new PropertyInfo();
    pi.setName("pCodigo_Entidade");
    pi.setValue(pCodigo_Entidade);
    pi.setType(Convenio_Conselho_Grid_BD.class);
    request.addProperty(pi);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE httpTransport = new HttpTransportSE(oFinanceiro.SOAP_ADDRESS);

    SoapObject response = null;
    try {
        httpTransport.call(oFinanceiro.SOAP_ACTION, envelope);
        response = (SoapObject) envelope.bodyIn;
    } catch (Exception exception) {
        Log.d("Erro", exception.toString());
    }
    return response;
}

And when I return this object, I loop the properties to get the values and populate a list of the objects I needed.

 SoapObject ob = SG_Smartphone_NG.Convenio_Conselho().Pesquisar_Convenios(1);

            for (int i = 0; i < ob.getPropertyCount(); i++) {
                SoapObject ob2 = (SoapObject) ob.getProperty(i);

                for (int j = 0; j < ob2.getPropertyCount(); j++) {
                    SoapObject ob3 = (SoapObject) ob2.getProperty(j);
                    Convenio_Conselho_Grid_BD oConvenio = new Convenio_Conselho_Grid_BD();

                    oConvenio.setCodigo(Short.parseShort(ob3.getProperty(0).toString()));

Etc ...

    
07.05.2018 / 15:45