为了连接到 .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)
利亚卡特