我有一个连接到 Web 服务并返回 SoapObject 的函数。如果我在没有 AsyncTask 的情况下直接调用此函数,则此函数可以正常工作,但以下代码会引发异常。有什么建议么?
private class LoginTask extends AsyncTask<String, Object, Object> {
protected SoapObject doInBackground(String... params) {
try
{
return callWebService("a","a");
}
catch (Exception e)
{
return null;
}
}
protected void onPostExecute(SoapObject result) {
setErrorText(result);
}
}
private SoapObject callWebService(String UserName, String Password) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("UserName", UserName);
request.addProperty("Password", Password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse(); //this code causes the problem
return response;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (XmlPullParserException e) {
e.printStackTrace();
return null; //Directly jumps to here
}
}