Android consuming web service soap

0

I'm developing an application to fetch on the response server, I send the ticket number and its type. But when I send the data he does not send me a return, what can I be doing wrong?

package br.com.testes.webservicesoapxml;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;


public class MainActivity extends AppCompatActivity implements View.OnClickListener, Runnable {
private EditText edtSequencia;
private EditText edtTipo;
private Button buttonOk;
private TextView txtResultado;
private String chaveIntegracao = "sL8xlbkw2454kLx3i803981804000107Lxd5yV063sKc3gHx9344";
private Handler handler = new Handler();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    edtSequencia = (EditText) findViewById(R.id.edtSequencia);
    edtTipo = (EditText) findViewById(R.id.edtTipo);
    buttonOk = (Button) findViewById(R.id.buttonOk);
    txtResultado = (TextView) findViewById(R.id.txtResultado);

    buttonOk.setOnClickListener(this);


}


@Override
public void onClick(View v) {
    Thread t = new Thread();
    t.start();

}

@Override
public void run() {
    int sequencia = Integer.parseInt(edtSequencia.toString());
    String tipo = edtTipo.toString();

    WebService ws = new WebService();

    try {
      ws.enviaLinhaDigitavel(this.chaveIntegracao, sequencia, tipo);


        handler.post(new Runnable() {
            @Override
            public void run() {

            }
        });

    } catch (IOException e) {
        e.printStackTrace();
        Log.e("MainActivity", "Erro", e);
    } catch (XmlPullParserException e) {
        e.printStackTrace();
        Log.e("MainActivity", "Erro", e);
    }


}
}

package br.com.testes.webservicesoapxml;

import android.util.Log;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

/**
 * Created by rodri on 26/09/2016.
 */

public class WebService {


    public String enviaLinhaDigitavel(String chaveIntegracao, int sequencia, String tipo) throws IOException, XmlPullParserException {
        SoapObject soap = new SoapObject("urn:RouterBoxMobile", "EnviarLinhaDigitavel");
        soap.addProperty("ChaveIntegracao",chaveIntegracao);
        soap.addProperty("Sequencia", sequencia);
        soap.addProperty("tipo", tipo);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(soap);
        HttpTransportSE httpTransportSE = new HttpTransportSE("http://177.8.248.43:81/routerbox/ws_mobile/rbx_server_mobile.php?wsdl");


        Log.i("DEVMEDIA", "Chamando WebService para consulta de CEP");


        httpTransportSE.call("CadastrarAuteticacao",envelope);

        Object resultado = envelope.getResponse();


        return resultado.toString();
    }
}

  Esse é o serviço que estou trabalhando.

    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:env="EnviaLinhaDigitavel">
   <soapenv:Header/>
   <soapenv:Body>
      <env:EnviaLinhaDigitavel soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <Autenticacao xsi:type="urn:Autenticacao" xmlns:urn="urn:RouterSistemas">
            <ChaveIntegracao xsi:type="xsd:string"></ChaveIntegracao>
         </Autenticacao>
         <DadosBoleto xsi:type="urn:DadosBoleto" xmlns:urn="urn:RouterSistemas">
            <Sequencia xsi:type="xsd:int">191</Sequencia>
            <Enviar xsi:type="xsd:string">N</Enviar>
         </DadosBoleto>
      </env:EnviaLinhaDigitavel>
   </soapenv:Body>
</soapenv:Envelope>
    
asked by anonymous 26.09.2016 / 21:23

1 answer

1

Try moving your call to an asynchronous call:

public String enviaLinhaDigitavel(String chaveIntegracao, int sequencia, String tipo) throws IOException, XmlPullParserException {
        SoapObject soap = new SoapObject("urn:RouterBoxMobile", "EnviarLinhaDigitavel");
        soap.addProperty("ChaveIntegracao",chaveIntegracao);
        soap.addProperty("Sequencia", sequencia);
        soap.addProperty("tipo", tipo);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(soap);
        HttpTransportSE httpTransportSE = new HttpTransportSE("http://177.8.248.43:81/routerbox/ws_mobile/rbx_server_mobile.php?wsdl");






new AsyncTask<Void,String,String>(){

            @Override
            protected String doInBackground(Void... voids) {
               Log.i("DEVMEDIA", "Chamando WebService para consulta de CEP");


        httpTransportSE.call("CadastrarAuteticacao",envelope);

        Object resultado = envelope.getResponse();


        return resultado.toString();
            }

            @Override
            protected void onPostExecute(String string) {
               // faça alguma coisa com seu retorno
            }
        }.execute();

}

The only thing you need to pay attention to is that your method will no longer return the string, you need to pass the result to the onPostExecute() method, it's best to have a look at how an AsyncTask works

    
26.09.2016 / 22:48