【问题标题】:Android use ksoap2 to connect wcf webservice sometimes fail connect to serverAndroid 使用 ksoap2 连接 wcf webservice 有时无法连接到服务器
【发布时间】:2018-08-28 11:54:34
【问题描述】:

我有一个问题,当我使用 ksoap2 连接 wcf webservice 时,有时我已经成功连接并获取数据,但有时失败(socketexception:无法连接到服务器)互联网在所有情况下都可以。

我已经为每个连接设置了超时时间是 10000ms

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,10000);

【问题讨论】:

    标签: android web-services wcf-data-services android-ksoap2


    【解决方案1】:

    您必须优雅地处理此类错误。请记住,移动设备上的互联网可能不稳定。这取决于信号。

    例如,手机可能正在从 GPRS 信号转换为 3G 信号。这意味着它有效地重新启动了互联网连接。

    我会做以下事情:

     try
     {
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,10000);
     }
     except(Exception e)
     {
        //Do something with the exception
        // You can try to reconnect.
        // You can report the error to the user.
        // You can do some network diagnostics here.
        // The thing is that networks on mobiles are unreliable so handle the exception.
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      相关资源
      最近更新 更多