我在Android项目中使用了上面的SOAP对象,以便连接到.NET Web服务。应用程序运行正常,直到我做了一些更改,并且还增加/减少了目标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;
}
下面的Log Cat:
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)
Liaqat
答案 0 :(得分:4)
在我有另外两个例外情况继续使用该应用程序之后解决了这个问题,并且在我的另一个问题上回复并建议使用AsyncTask。一旦AsyncTask工作,这个错误也消失了。所以,猜测可以假设问题是由在GUI活动上进行网络操作的同样问题引起的。
非常感谢您的帮助。 Liaqat。
答案 1 :(得分:2)
有趣的是,在增加/减少目标API并使用清单时,请确保您拥有互联网权限:
<uses-permission android:name="android.permission.INTERNET" />