Search code examples
androidksoap2android-ksoap2

to check if KSOAP2 web-service is up and running


    private String METHOD_NAME = "schedule";
    private String NAMESPACE = "http://calculate.backend.web.org";
    private String SOAP_ACTION = NAMESPACE + METHOD_NAME; 
    private static final String URL = "http://192.168.0.4:8080/AndroidBackEnd/services/Calculate?wsdl";

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("username",username);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION,envelope);
            Object result = envelope.getResponse();

How to verify if the WEB-SERVICE is up and running from the client?


Solution

  • If your web-service is down, then Android throws a SocketTimeoutException when it is unable to connect to it.

    You can manually set the timeout duration of your connection via

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeoutDuration);

    or let the connection get timed out after its default timeout duration.

    So, you can catch that exception in your code and get to know that the web-service is down.