0
I’m developing an application to search the response server, I send the boleto number and your type. Only when I send the data he doesn’t send me a return, what I might 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>
Returns an error ?
– Lucas Queiroz Ribeiro
@Lucasqueirozribeiro Nothing has returned!
– rodrigo.oliveira
Strange, I tested your envelope at the address and is returning correctly I think, you came to see the envelope generated with Ksoap methods if it was the same as expected ? If yes, there may be some problem with the connection itself
– Lucas Queiroz Ribeiro
Put some breakpoints in your code (mainly in the result.toString();) and check in the Debugger if the result object is really null, sometimes it’s something in getresponse() or toString itself()
– Lucas Queiroz Ribeiro
@Lucasqueirozribeiro, I’m starting a few days in android development. I did a debugging but can’t see what comes in the result, how can I get the result that’s coming from the result and put in Textview? The Envelope I tested by Soapui it works. must be doing something wrong in the code.
– rodrigo.oliveira
@Lucasqueirozribeiro, on the Result line appears this Suspend thread.
– rodrigo.oliveira
By clicking next to the number of the line you add a Breakpoint, if you put a breakpoint after an action, in the debug window you can see the variable and if you click on it you see everything it has, so you can see if the answer is receiving something.
– Lucas Queiroz Ribeiro
This Suspend Thread error can occur while trying to make an internet call on the main thread, you are doing this without any asynchronous calls ?
– Lucas Queiroz Ribeiro
@Lucasqueirozribeiro, is without asynchronous call.
– rodrigo.oliveira
From API 3 you cannot make internet calls on the main thread, I will post an answer with an example and you move your call into the method.
– Lucas Queiroz Ribeiro