Question

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?

Was it helpful?

Solution

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 )
               {}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top