检查KSOAP2 Web服务是否已启动并正在运行

时间:2012-08-23 09:01:51

标签: android ksoap2 android-ksoap2

    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();

如何验证WEB-SERVICE是否已从客户端启动并运行?

1 个答案:

答案 0 :(得分:1)

如果您的网络服务已关闭,那么Android无法连接时会抛出SocketTimeoutException

您可以通过

手动设置连接的超时时间

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeoutDuration);

或让连接在其默认超时持续时间后超时。

因此,您可以在代码中捕获该异常,并了解Web服务已关闭。