Cast in a Soapobject

Asked

Viewed 114 times

1

I have the following code to consume one 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 will return the object, it gives the following error:

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

I’ve tried a lot of casting and nothing works. This type was created in the .net and created the same type with the same properties in the project android

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 returning this object, loop the properties to get the values and fill in 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....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.