我已经按照谷歌开发者网站上的教程实现了我的SOAP webservice,现在我正在编写一个Android应用程序,它使用ksoap2库调用可用服务并显示结果(现在在textview中)。 这就是代码:
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都是null。怎么了?在appengine服务器日志,我可以看到Android应用程序要求wsdl文件,但没有发送服务请求。有什么问题(wsdl文件可以在我的代码中写入ad url)?
答案 0 :(得分:1)
Ksoap不使用wsdl(因此不会请求它)。您应该传递服务URL而不是wsdl url。您可以在wsdl(服务说明部分中location
元素的属性address
)中找到服务网址。