gpt4 book ai didi

Android KSOAP2 抛出 SocketTimeoutException

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

为了连接到 .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)

利亚卡特

最佳答案

在我的应用程序出现另外几个异常之后解决了这个问题,一些其他人对我的其他问题回答并建议使用 AsyncTask。一旦让 AsyncTask 工作,这个错误也消失了。所以,假设这个问题是由对 GUI Activity 进行网络操作的相同问题引起的,这很好。

非常感谢您的帮助。利亚卡特。

关于Android KSOAP2 抛出 SocketTimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14573637/

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