0
Good afternoon, I am having a problem connecting to the webservice. I am using ksoap2 library.
public class CallSOAP
{
public final String SOAP_ACTION = "http://tempuri.org/yteste";
public final String OPERATION_NAME = "yteste";
public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
public final String SOAP_ADDRESS = "http://192.168.2.101/WebService.asmx";
public CallSOAP()
{
}
public String Call(EditText edtQtde)
{
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
SoapPrimitive response = null;
try
{
httpTransport.call(SOAP_ACTION, envelope);
response = (SoapPrimitive)envelope.getResponse();
}
catch (Exception exception)
{
edtQtde.setText("erro do call");
//response = exception.toString();
}
return response.toString();
}
The error occurs in "Sponse = (Soapprimitive)envelope.getresponse();", and ends up falling in catch() where I put an error message.
Main class:
public class MainActivity extends AppCompatActivity {
Button btnAdicionar;
EditText edtQtde;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnAdicionar = (Button)findViewById(R.id.btnAdicionar);
edtQtde = (EditText)findViewById(R.id.edtQtde);
final AlertDialog ad=new AlertDialog.Builder(this).create();
btnAdicionar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
CallSOAP cs = new CallSOAP();
try
{
String resp = cs.Call(edtQtde);
ad.setMessage(resp.toString());
}catch(Exception ex)
{
ad.setMessage("erro");
}
ad.show();
}
});
}
}
Note: The yteste function only returns a string.
Thank you
What the stack trace of
Exception
which is sent to catch?– Igor Castañeda Ferreira
"android.os.Networkonmainthreadexception" . NOTE: I use my mobile phone to test applications
– Vitor Herrmann