我连接到webservice以下载我的应用程序的主数据。因此,在单个下载中,应用程序将需要使用不同的索引来调用Web服务。
在此期间, HttpTransportSE.call 方法有时会返回某些索引的 NullPointerException ,否则它可以正常工作。
我的通话功能是:
public String SoapAction(String[] values){
String[] data = new String[] { "CompanyID", "Username", "Password", "indexNo", "DataString","lDate" };
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
for(int i = 0; i < data.length; i++){
PropertyInfo property = new PropertyInfo();
property.setName(data[i]);
property.setNamespace(NAMESPACE);
property.setType(PropertyInfo.STRING_CLASS);
property.setValue(values[i]);
request.addProperty(property);
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
try{
HttpTransportSE http = new HttpTransportSE(URL);
http.debug = true;
System.setProperty("http.keepAlive", "false");
http.call(SOAP_ACTION, envelope);
}catch (IOException e1) {
e1.printStackTrace();
return "serverError";
} catch (XmlPullParserException e1) {
e1.printStackTrace();
return "serverError";
} catch (Exception e) {
e.printStackTrace();
return "serverError";
}
SoapPrimitive resultString = null;
try{
resultString = (SoapPrimitive)envelope.getResponse();
}catch (SoapFault e) {
e.printStackTrace();
return "serverError";
}
if(resultString != null){
return resultString.toString();
} else {
return "serverError";
}
}
我做了很多谷歌搜索,但找不到解决方案
这是堆栈跟踪:
02-06 14:01:14.136:W / System.err(1504):java.lang.NullPointerException
02-06 14:01:14.136:W / System.err(1504):at org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)
02-06 14:01:14.136:W / System.err(1504):at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:167)
02-06 14:01:14.136:W / System.err(1504):at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)
02-06 14:29:50.026:W / System.err(1504):at com.c2info.engine.WebServiceConnection.SoapAction(WebServiceConnection.java:49)
02-06 14:29:50.026:W / System.err(1504):at com.c2info.engine.DownloadData.downloadTasks(DownloadData.java:800)
02-06 14:29:50.026:W / System.err(1504):at com.c2info.engine.DownloadData $ 3.run(DownloadData.java:187)
答案 0 :(得分:1)
我从不添加像你的
这样的属性request.addProperty("data", "value");
试试这个:
PropertyInfo property = new PropertyInfo();
{
property.name = "data";
property.setNamespace(NAMESPACE);
property.type = PropertyInfo.STRING_CLASS;
property.setValue("value");
}
request.addProperty(property);
也尝试使用
SoapEnvelope.VER11
而不是VER12
并添加原始
envelope.implicitTypes = true;
您是否在AndroidMAnifest.xml中添加了此权限?
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
答案 1 :(得分:0)
在做了一些研究之后,我发现它发生在服务器繁忙时,当服务器处理你的请求时,HttpTransportSE调用方法超时。默认超时值为20秒。所以,要克服这一点,:
设置合适的超时值
HttpTransportSE http = new HttpTransportSE(URL,30000);
将http.call方法包含在while循环中,并重试“N”,直到获得有效响应为止