Getting response from WebService with Ksoap

1

I have a Web service that returns this data:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <LISTACLIENTESRESPONSE xmlns="http://localhost:8093/">
         <LISTACLIENTESRESULT>
            <ACLIENTE>
               <STCLIENTE>
                  <CCODIGO>000001</CCODIGO>
                  <CRAZAO>PEDRO DA SILVA</CRAZAO>
                  <CMUNICIPIO>SAO PAULO</CMUNICIPIO>
                  <CVENDEDOR>JOAO</CVENDEDOR>
               </STCLIENTE>
               <STCLIENTE>
                  <CCODIGO>000002</CCODIGO>
                  <CRAZAO>JOSE</CRAZAO>
                  <CMUNICIPIO>SAO PAULO</CMUNICIPIO>
                  <CVENDEDOR>PAULO</CVENDEDOR>
               </STCLIENTE>
               <STCLIENTE>
                  <CCODIGO>000003</CCODIGO>
                  <CRAZAO>LETICIA</CRAZAO>
                  <CMUNICIPIO>SAO PAULO</CMUNICIPIO>
                  <CVENDEDOR>PEDRO</CVENDEDOR>
               </STCLIENTE>
            </ACLIENTE>
            <CMENSAGEM>3 Clientes Localizados</CMENSAGEM>
         </LISTACLIENTESRESULT>
      </LISTACLIENTESRESPONSE>
   </soap:Body>
</soap:Envelope>

In my Android studio project, I can connect and send the data to WS but I am not understanding how to retrieve the data provided by WS.

envelope.setOutputSoapObject(buscarClientes);//Metodo esta correto

HttpTransportSE http = new HttpTransportSE(URL);

try {
    SoapObject soapObject = 
    (SoapObject)resposta.getProperty("ACLIENTE");
    for(int i = 0; i < soapObject.getPropertyCount(); i++) {
        soapObject.getProperty(1).toString());
        Cliente cliente = new Cliente();
        cliente.setCodigo(soapObject.getProperty("CCODIGO").toString());                
        cliente.setRazao(soapObject.getProperty("CRAZAO").toString());
        cliente.setMun(soapObject.getProperty("CMUNICIPIO").toString());
        listaClientes.add(cliente);
    }
} catch (Exception e){
    return listaClientes;
}

How do I recover this data? Return is an array of clients and a message.

I ran this code:

SoapObject resposta = (SoapObject) envelope.getResponse(); 
String clientes = envelope.getResponse().toString(); 
Log.i("CLIENTE",clientes);

The return in the Log was this: anyType {ACLIENT = anyType {STCLIENTE = anyType {CCODIGO = 000819; COMPANY = SAO PAULO; CRAZY = CLIENT; CVENDEDOR = FIR1; }; STCLIENT = anyType {CCODIGO = 001951; CMUNICIPIO = SANTOS; CRAZAO = CUSTOMER 2; CVENDEDOR = FIR2; };} CMENSAGE = 2 Localized Clients.

You have returned all data from the Web Service.

    
asked by anonymous 26.10.2018 / 12:45

1 answer

0

I managed to resolve. I tried to solve for Parse but it did not work, because when I pass the Ksoap Object to string, it messes up all the XML code, placing brackets and removing some tags.

I used Ksoap itself to solve.

     HttpTransportSE http = new HttpTransportSE(URL);

    try {

        http.call(METODOLISTA,envelope);
        SoapObject resposta = (SoapObject) envelope.getResponse();
        String mensagem = resposta.getPrimitiveProperty("CMENSAGEM").toString();
        SoapObject respostaClientes = (SoapObject) resposta.getProperty("ACLIENTE");

        for(int x = 0; x < respostaClientes.getPropertyCount(); x++) 
       {
            SoapObject clienteOb = (SoapObject) respostaClientes.getProperty(x);
            Cliente cliente = new Cliente();
            cliente.setCodigo(clienteOb.getPrimitiveProperty("CCODIGO").toString());
            cliente.setRazao(clienteOb.getPrimitiveProperty("CRAZAO").toString());
    cliente.setMunicipio(clienteOb.getPrimitiveProperty("CMUNICIPIO").toString());
            cliente.setVendedor(clienteOb.getPrimitiveProperty("CVENDEDOR").toString());
            listaClientes.add(cliente);
       }

    } catch (Exception e)
    {
           return listaClientes;
        }

The line - SoapObject response = (SoapObject) envelope.getResponse () returned the entire XML.

As the "CMENSAGEM" tag is on the first level, I can retrieve it with the command:

String message = response.getPrimitiveProperty ("CMENSAGE"). toString ();

Dai came the cat's leap, the "ACLIENTE" tag is an array of "STCLIENT" tags. With the command below - responseCustomers - received the XML from the tag "ACLIENTE"

SoapObject responseClients = (SoapObject) response.getProperty ("ACLIENT");

Dai was just going through the Customer response object and going capturing the data It worked ........

    
31.10.2018 / 02:02