Boa tarde, estou com um problemas para me conectar ao webservice. Estou usando a biblioteca ksoap2.
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();
}
O erro ocorre em "response = (SoapPrimitive)envelope.getResponse();", e acaba caindo no catch() onde eu coloquei uma mensagem de erro.
Classe principal:
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();
}
});
}
}
Observação: a função yteste apenas retorna um string.
Obrigado
Exception
que é enviada para o catch?