我按照谷歌开发者网站上的教程实现了我的 SOAP 网络服务,现在我正在编写一个调用可用服务并使用 ksoap2 库显示结果(现在在文本视图中)的 android 应用程序。那是代码:
public class DownloadDataTask extends AsyncTask<Void, Void, SoapObject> {
private static String METHOD_NAME = "getData";
private static String SOAP_ACTION = "http://example.com/getData";
private static String WSDL_URL = "http://arduino-data-server.appspot.com/FunctionsService.wsdl";
private static String NAMESPACE = "http://example.com/";
private MainActivity caller_activity;
public DownloadDataTask(MainActivity a) {
caller_activity = a;
}
@Override
protected SoapObject doInBackground(Void... arg0) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(WSDL_URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.getResponse();
return result;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(SoapObject result) {
TextView tw = (TextView) caller_activity.findViewById(R.id.text_view);
if (result == null) {
tw.setText("NULL");
} else {
tw.setText(result.getName());
}
}
}
但每次,结果 SoapObject 都是空的。怎么了?在 appengine 服务器日志上,我可以看到 android 应用程序请求 wsdl 文件,但没有发送服务请求。出了什么问题(wsdl 文件可用广告 url 写在我的代码中)?