3

I've a function that connects to a web service and returns the SoapObject. This function works without a problem if I call it directly without the AsyncTask but the following code throws an exception. Any suggestions?

 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
    }

}

1 Answers1

0

If you change your declaration of your task from:

    private class LoginTask extends AsyncTask<String, Object, Object>

to

    private class LoginTask extends AsyncTask<String, Object, SoapObject>

your onPostExecute() should execute.

Mark Semsel
  • 7,125
  • 3
  • 29
  • 27