1

我连接到网络服务以下载我的应用程序的主数据。因此,在一次下载中,应用程序将需要使用不同的索引多次调用 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): 在 org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)

02-06 14:01:14.136: W/System.err(1504): 在 org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:167)

02-06 14:01:14.136: W/System.err(1504): 在 org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)

02-06 14:29:50.026: W/System.err(1504): 在 com.c2info.engine.WebServiceConnection.SoapAction(WebServiceConnection.java:49)

02-06 14:29:50.026: W/System.err(1504): 在 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)

4

2 回答 2

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>
于 2013-02-06T07:28:23.277 回答
1

经过一番研究,我发现它发生在服务器繁忙时,当服务器处理您的请求时,HttpTransportSE 调用方法超时。默认超时值以 20 秒为单位。因此,为了克服这一点,:

  • 设置合适的超时值

    HttpTransportSE http = new HttpTransportSE(URL, 30000);

  • 将 http.call 方法包含在一个 while 循环中并重试直到'N'次,直到你得到一个有效的响应

于 2013-09-04T05:41:08.167 回答