3

I am using this code for calling webservice method by ksoap2:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
                    TimeOutInSeconds * 1000);

            try {
                androidHttpTransport.call(soapAction, envelope);
            } catch (Exception e) {

            }

            SoapObject so = (SoapObject) envelope.getResponse();

In some situations webserivce does not response to my request immediately and app is waiting at line androidHttpTransport.call(soapAction, envelope); and user wants to cancel the request. How can I let user to cancel the call method?

Bob
  • 22,810
  • 38
  • 143
  • 225

1 Answers1

0

I am hoping your calling this line from a background thread and not the UI/main thread. In fact on HC+ this should crash by default due to StrictMode.

Canceling network calls while they are in progress can be tricky. You might have to keep a reference to the connection itself and call a shutdown() method from your main thread. There is no guarantees that canceling would be invoked immediately though. It will depend on the implementation of the connection itself.

I am assuming you are using kSOAP which I am not sure if it offers a cancel() mechanism.

Another way is to wait for the first call to finish and then make another network call to undo the operation on the server. This will ensure your state is in sync.

dnkoutso
  • 6,041
  • 4
  • 37
  • 58