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 am not understanding how to recover 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? The 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);
O retorno no Log foi esse: anyType{ACLIENTE=anyType {STCLIENTE=anyType{CCODIGO=000819; CMUNICIPIO=SAO PAULO; CRAZAO=CLIENTE; CVENDEDOR=FIR1; };STCLIENTE=anyType{CCODIGO=001951; CMUNICIPIO=SANTOS;CRAZAO=CLIENTE 2; CVENDEDOR=FIR2; };}CMENSAGEM=2 Clientes Localizados.
Returned all Web Service data.
See if
String clientes = envelope.getResponse().toString();
help you. This should convert the array contained in the Response intoString
, that then you will manipulate to fill your objectCliente
. If it works, let me know and I’ll create a proper response.– StatelessDev
How to manipulate this string to get separate information?
– Andre B
One question: in your original code, do you get to receive as an answer that XML you put in the question? If yes, it is only a matter of you using a parser XML, which will map each XML client to a class
Cliente
you can create with the properties brought in in XML. Nor would you need to convert toString
.– StatelessDev
The return returned as posted above. In the program Sopui the return appears as XML code with the tags between <>. But in the string the tags are between {}. But this return is composed of the following structure: On the first level I have two tags: TAG CMENSAGEM (which is a string) and TAG ACLIENTE (which is an array of clients). For TAG ACLIENTE, there is level 2 which is the STCLIENT tag (which are the array clients) and within this tag, has the Tags: CCODIGO; CMUNICIPIO, CRAZAO and CVENDEDOR (which are the information of each client. In this structure can I use the XML parse? Coo do?
– Andre B
This will help you: https://www.javacodegeeks.com/2013/05/parsing-xml-using-dom-sax-and-stax-parser-in-java.html
– StatelessDev