ksoup2 org.xmlpull.v1.Xmlpullparserexception:

Asked

Viewed 96 times

2

I’m trying to make a query in the WEB SERVER implemented in PHP in this link.

In the web service I have to send a request by passing the parameters Imei, password, operation.

public class cargaColetaDao {

private static final String URL = "http://www.termaco.com.br/cargasmobile/cargasmobiledev.php?wsdl";
private static final String targetNamespace = "urn:server.smbc";
private static final String SMBC = "smbc";


public void smbcRequest(smbc smbc) {

    SoapObject carregarDados = new SoapObject(targetNamespace, SMBC);
    SoapObject spSmbc = new SoapObject(targetNamespace, "smbc");

    spSmbc.addProperty("<smbc>", "smbc");
    spSmbc.addProperty("<imei>", smbc.getImei());
    spSmbc.addProperty("<senha>", smbc.getSenha());
    spSmbc.addProperty("<operacao>", smbc.getOperacao());

    carregarDados.addSoapObject(spSmbc);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(carregarDados);

    envelope.implicitTypes = true;

    HttpTransportSE http = new HttpTransportSE(URL);
    try {
        http.call("urn:smbc", envelope);
        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        Log.e("Resultado ****:", response.toString());

    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }


}

He was supposed to return the following XML...

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:smbcResponse xmlns:ns1="urn:server.smbc">
      <return xsi:type="xsd:string">
        <![CDATA[<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>
          </item>
          <retorno>1</retorno>
          <descricao>Carga Realizada com sucesso.</descricao>
        </smbc>]]>
      </return>
    </ns1:smbcResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

but he’s casting the exception saying that the namespace is not right.

 org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <definitions targetNamespace='urn:server.smbc'>@2:431 in java.io.InputStreamReader@2ed5f2c1) 

I’ve been trying to figure it out for a week and I can’t.

From now on, thank you very much.

1 answer

1

Solved. Thus below.

public ArrayList<Carga> smbcRequest(smbc smbc) {     
    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);

// Soapobject answer = (Soapobject) envelope.bodyIn;

             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());
            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;
}

}

  • I’m going through a problem similar to this, could help me?

Browser other questions tagged

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