1

为了连接到 .NET Web 服务,我在我的 Android 项目中将上述库用于 SOAP 对象。该应用程序运行良好,直到我进行了一些更改并增加/减少了目标 API。它开始抛出 SocketTimeoutException 并且不会消失。

我正在使用Android 开发者工具构建:v21.0.0-519525

任何帮助表示赞赏。

    private static final String NAMESPACE = "https://monitor.co.uk/";
    private static final String URL = "https://monitor.co.uk/WebService.asmx";

    private static final String GET_ID_METHOD = "GetId";
    private static final String GET_ID_SOAP_ACTION = "https://monitor.co.uk/GetId";
    public static String callGetIdWebService(String pass, String id, Context context)
    {
      String sRes = "";
      try 
      { 

        SoapObject request = new SoapObject(NAMESPACE, GET_ID_METHOD);

            PropertyInfo pi = new PropertyInfo();
            pi.setName("pass");
            pi.setValue(pass.toString());//"pass");// 
            pi.setType(pass.getClass());
            request.addProperty(pi);

            PropertyInfo pi2 = new PropertyInfo();
            pi2.setName("id");
            pi2.setValue(id.toString());
            pi2.setType(id.getClass());
            request.addProperty(pi2);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);  
            envelope.implicitTypes = true;

            HttpTransportSE httpTransport = new HttpTransportSE(URL);

            httpTransport.debug = true;

            httpTransport.call(GET_ID_SOAP_ACTION, envelope);
            Object response = envelope.getResponse();

            httpTransport.debug = true;
            if(response.toString().equals("-1"))
            {
                sRes = "No records";
            }
            else
            {
                sRes = response.toString();
            }
      } 

      catch (Exception e) 
      {
        e.printStackTrace();
        Log.i("EXCEPTION...", e.toString());

      }
      return sRes;
    }

日志猫如下:

01-28 17:39:34.213: W/System.err(16378): java.net.SocketTimeoutException
01-28 17:39:34.218: W/System.err(16378):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:130)
01-28 17:39:34.218: W/System.err(16378):    at com.example.notificationmanager.CreateNotificationActivity.callGetIdWebService(CreateNotificationActivity.java:94)
01-28 17:39:34.218: W/System.err(16378):    at com.example.notificationmanager.CreateNotificationActivity.createNotification(CreateNotificationActivity.java:37)
01-28 17:39:34.218: W/System.err(16378):    at java.lang.reflect.Method.invokeNative(Native Method)
01-28 17:39:34.218: W/System.err(16378):    at java.lang.reflect.Method.invoke(Method.java:511)
01-28 17:39:34.218: W/System.err(16378):    at android.view.View$1.onClick(View.java:3095)
01-28 17:39:34.218: W/System.err(16378):    at android.view.View.performClick(View.java:3627)
01-28 17:39:34.223: W/System.err(16378):    at android.view.View$PerformClick.run(View.java:14329)
01-28 17:39:34.223: W/System.err(16378):    at android.os.Handler.handleCallback(Handler.java:605)
01-28 17:39:34.223: W/System.err(16378):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-28 17:39:34.223: W/System.err(16378):    at android.os.Looper.loop(Looper.java:137)
01-28 17:39:34.223: W/System.err(16378):    at android.app.ActivityThread.main(ActivityThread.java:4511)
01-28 17:39:34.223: W/System.err(16378):    at java.lang.reflect.Method.invokeNative(Native Method)
01-28 17:39:34.228: W/System.err(16378):    at java.lang.reflect.Method.invoke(Method.java:511)
01-28 17:39:34.228: W/System.err(16378):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-28 17:39:34.228: W/System.err(16378):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-28 17:39:34.228: W/System.err(16378):    at dalvik.system.NativeStart.main(Native Method)

利亚卡特

4

2 回答 2

4

在我的应用程序发生了另外几个异常之后,我得到了这个修复,其他一些人在我的另一个问题上回答并建议使用 AsyncTask。一旦让 AsyncTask 工作,这个错误也消失了。因此,假设问题是由在 GUI 活动上进行网络操作的相同问题引起的,猜测这很好。

非常感谢你的协助。利亚卡特。

于 2013-03-04T11:52:25.180 回答
2

有趣的是,在增加/减少目标 API 和使用清单时,请确保您拥有 Internet 权限:

<uses-permission android:name="android.permission.INTERNET" />
于 2013-01-29T11:46:22.877 回答