2
    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 是否已从客户端启动并运行?

4

1 回答 1

1

如果您的 Web 服务已关闭,那么 AndroidSocketTimeoutException在无法连接到它时会抛出一个错误。

您可以通过手动设置连接的超时持续时间

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeoutDuration);

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

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

于 2012-08-23T12:58:17.077 回答