gpt4 book ai didi

android - 检查 KSOAP2 网络服务是否已启动并正在运行

转载 作者:行者123 更新时间:2023-11-29 02:02:08 26 4
gpt4 key购买 nike

    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 是否已启动并正在运行?

最佳答案

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

您可以通过

手动设置连接的超时时间

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, timeoutDuration);

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

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

关于android - 检查 KSOAP2 网络服务是否已启动并正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12088218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com