7

I am using ksoap2 to create a user registration application in Android.

When I send request to the server and there is no response within 10 seconds I want to prompt the user with a "Try again" message. If the server responds within 10 seconds I want the program to proceed without the message.

How can I achieve this? Is there a TimerTask or any method for Timeout in KSoap2?

Tjaart
  • 3,912
  • 2
  • 37
  • 61
Urvashi
  • 439
  • 2
  • 6
  • 6
  • follow this answer and download latest ksoap 2 library [http://stackoverflow.com/questions/17478082/android-ksoap-connection-timed-out-when-using-more-than-one-device-on-same-wirel/32223807#32223807][1] – Amol Suryawanshi Aug 26 '15 at 10:20

1 Answers1

12
private String METHOD_NAME;
    private String NAMESPACE;
    private String SOAP_ACTION;
    private String URL;
private int TimeOut=3000;//
    private SoapObject so;
    SoapSerializationEnvelope envelope;
    HttpTransportSE androidHttpTransport;
 try
               {      

                      METHOD_NAME = "myutility";
                      NAMESPACE = "http://";
                      SOAP_ACTION = NAMESPACE + METHOD_NAME;
                      Thread.sleep(2000);  
                      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                      envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                      envelope.setOutputSoapObject(request);

                      URL = "http://www.example.com";
                      androidHttpTransport = new HttpTransportSE(URL,Time_Out);
                      androidHttpTransport.call(SOAP_ACTION,envelope);
                      so = (SoapObject)envelope.bodyIn;
                      String s=so.toString();
                      //Your processing here
               }
               catch(InterruptedException e)
               {
                   //When timeout occurs handles this....

               }
catch( Exception e )
               {}
Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104