问题
I connect to a webservice to download master data for my app. So, in a single download the app will need to call the webservice a no of times with different indexes.
During this, HttpTransportSE.call method returns NullPointerException for some indexes sometimes, otherwise it works fine.
My calling function is :
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";
}
}
I did quite a bit of googling, but couldn't find a solution
Here's the stacktrace:
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)
回答1:
I never add the properties like your
request.addProperty("data", "value");
Try this:
PropertyInfo property = new PropertyInfo();
{
property.name = "data";
property.setNamespace(NAMESPACE);
property.type = PropertyInfo.STRING_CLASS;
property.setValue("value");
}
request.addProperty(property);
Also try to use
SoapEnvelope.VER11
instead of VER12
and add raw
envelope.implicitTypes = true;
And did you add this permission in AndroidMAnifest.xml?
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
回答2:
After doing some research, I found out that it happens when the server is busy and by the time the server processes your request, the HttpTransportSE call method times out. The default time-out values in 20s. So, to overcome this, :
Set a suitable time-out value
HttpTransportSE http = new HttpTransportSE(URL, 30000);
Enclose the http.call method in a while loop and retry till 'N' no of times till you get a valid response
来源:https://stackoverflow.com/questions/14723386/httptransportse-call-method-returns-nullpointerexception-frequently