How to use ksoap timeout in android?
Asked Answered
U

1

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?

Ulises answered 23/3, 2011 at 4:22 Comment(1)
follow this answer and download latest ksoap 2 library [#17478582Sterol
A
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 )
               {}
Acceleration answered 23/3, 2011 at 4:34 Comment(4)
You have to use ksoap2 library 2.5.2 with dependencies....Timeout Facility is not supported in ksoap2 2.4 library... You can download it from hereAcceleration
+1 Kartik for info, but the exception raised should be: catch (SocketTimeoutException e) { // Timed out }.Outstrip
@Kartik What is the Thread.sleep(2000); for? Is it necessary?Jeweller
@Jeweller : its just a demo thing showing long running operation.Acceleration

© 2022 - 2024 — McMap. All rights reserved.