【发布时间】:2014-11-03 16:16:51
【问题描述】:
对于我想使用Ksoap 和AsyncTask 的项目之一。现在在下面的代码中AsyncTask 可以正常工作,但是在将结果返回到WSDLHeper 后,我得到了错误的值。例如doInBackground 方法中this.result 的结果是:
[1, 4674070, {item=3000738; item=TSMS; item=30007227; item=30004444440000; item=30007227001401; item=50004066569100; item=50001717; item=500017171; item=5000171717; item=50001717007227; }]
返回值后我在tmp = String.valueOf(p.execute())有:
ir.tsms.wsdl.ProcessTask@417b65e0
在这一行:
tmp = String.valueOf(p.execute());
那是错的tmp必须有
[1, 4674070, {item=3000738; item=TSMS; item=30007227; item=30004444440000; item=30007227001401; item=50004066569100; item=50001717; item=500017171; item=5000171717; item=50001717007227; }]
返回。
我的代码:
public class WSDLHelper {
public SoapObject request;
public static String call(SoapObject rq){
String tmp;
ProcessTask p =new ProcessTask(rq);
tmp = String.valueOf(p.execute());
return tmp;
}
}
class ProcessTask extends AsyncTask<Void, Void, String > {
SoapObject req1;
private String result;
public ProcessTask(SoapObject rq) {
req1 = rq;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Void... params) {
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(this.req1);
AndroidHttpTransport transport = new AndroidHttpTransport(Strings.URL_TSMS);
transport.debug = true;
try {
transport.call(Strings.URL_TSMS + this.req1.getName(), envelope);
this.result = envelope.getResponse().toString();
} catch (IOException ex) {
Log.e("" , ex.getMessage());
} catch (XmlPullParserException ex) {
Log.e("" , ex.getMessage());
}
if (result.equals(String.valueOf(Integers.CODE_USER_PASS_FALSE))) {
try {
throw new TException(PublicErrorList.USERNAME_PASSWORD_ERROR);
} catch (TException e) {
e.printStackTrace();
}
return null;
}
return this.result;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
【问题讨论】:
-
如果您想获得正确的 tmp 值,请尝试在 onPostExecute() 方法中获取该值。
标签: android android-asynctask android-ksoap2