Get XML properties answered from web services server

Asked

Viewed 92 times

1

I am wanting to capture the values of XML properties answered by the server.

public ArrayList<Carga> smbcRequest(smbc smbc) {
    //instanciando variaveis
    PropertyInfo req = new PropertyInfo();
    ArrayList<Carga> lista = new ArrayList<>();

    SoapObject spSmbc = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    HttpTransportSE http = new HttpTransportSE(URL);

    System.setProperty("http.keepAlive", "false");
    http.debug = true;
    envelope.dotNet=true;
    //configuração das variaveis

    //req.setValue("&lt;smbc&gt;&lt;imei&gt;"+smbc.getImei()+"&lt;/imei&gt;&lt;senha&gt;"+smbc.getSenha()+"&lt;/senha&gt;&lt;operacao&gt;"+smbc.getOperacao()+"&lt;/operacao&gt;&lt;/smbc&gt;");

    req.setValue("<smbc><imei>"+smbc.getImei()+"</imei><senha>"+smbc.getSenha()+"</senha><operacao>"+smbc.getOperacao()+"</operacao></smbc>");
    req.namespace=NAMESPACE;
    req.name="smbc";
    req.type = String.class;

    spSmbc.addProperty(req);


    //add objectSoap in envelope to send web service
    envelope.setOutputSoapObject(spSmbc);
    envelope.implicitTypes = true;


    try {

        http.call(URL, envelope); 


             if (envelope.bodyIn instanceof SoapFault) {
            SoapFault sf = (SoapFault) envelope.bodyIn;
            throw new Exception(sf.getMessage());

        }
        else if (envelope.bodyIn instanceof SoapObject) {
             Log.e("Resultado ****:", envelope.bodyIn.toString()); 
/*nessa parte do código eu consigo obter como resposta do servidor o seguinte xml

smbcResponse{return=<smbc><operacao>1</operacao><item><empcodigo>FOR</empcodigo><codigo>1234</codigo><tipo>1</tipo><nome>Daniel</nome><endereco>Rua D, 300</endereco><ordem>1</ordem><status>2</status><parada>2</parada*/

and I want to take these values and to popular my objects (Load and item) and return in a list, but at the time of the casting of the envelope.bodyIn to vector Soapobject the java, says that can not do the casting.

            Vector<SoapObject> resposta = (Vector<SoapObject>) envelope.bodyIn;

            for (SoapObject soapObject : resposta) {
                Carga carga = new Carga();
                Item item = new Item();

                carga.setOperacao(soapObject.getProperty("operacao").toString() );
                carga.setRetorno(soapObject.getProperty("retorno").toString());
                carga.setDescricao(soapObject.getProperty("descricao").toString());

                item.setEmpCodigo(soapObject.getProperty("empcodigo").toString());
                item.setCodigo(soapObject.getProperty("codigo").toString());
                item.setEndereco(soapObject.getProperty("endereco").toString());
                item.setNome(soapObject.getProperty("nome").toString());
                item.setOrdem(soapObject.getProperty("ordem").toString());
                item.setParada(soapObject.getProperty("parada").toString());
                item.setStatus(soapObject.getProperty("status").toString());
                item.setTipo(soapObject.getProperty("tipo").toString());

                carga.setItem(item);
                lista.add(carga);
            }
         }
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (SoapFault soapFault) {
        soapFault.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lista;
}
}
  • Update uses question with Logcat showing error.

No answers

Browser other questions tagged

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