我正在尝试创建一个能够访问Web服务的Android应用程序。
我使用了本网站提供的示例:http://codeoncloud.blogspot.fr/2013/06/android-java-soap-web-service-access.html(第1部分)。
然而它根本不起作用,它一直显示" 1 USD = LKR"而不是" 1美元= 128.95 LKR"。然而,这段代码使用线程(因为经过大量研究,我发现网络请求需要在Android 3.0之后的后台线程上完成)。
我也试图创建一个AsyncTask,但它也不起作用。
以下是我的代码示例:
RetrieveFeedTask(我的AsyncTask):
public class RetrieveFeedTask extends AsyncTask <String, Void, Void>{
private Exception exception;
private static String webResponse = "";
protected void doInBackground(String NAMESPACE, String METHOD_NAME, String fromCurrency, String toCurrency, String SOAP_ACTION, String URL) {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("FromCurrency");
fromProp.setValue(fromCurrency);
fromProp.setType(String.class);
request.addProperty(fromProp);
PropertyInfo toProp =new PropertyInfo();
toProp.setName("ToCurrency");
toProp.setValue(toCurrency);
toProp.setType(String.class);
request.addProperty(toProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
setWebResponse(response.toString());
} catch (Exception e) {
this.exception = e;
return;
}
}
protected void onPostExecute (Void feed) {
}
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
return null;
}
protected Void doInBackground(String... params) {
// TODO Auto-generated method stub
return null;
}
public static String getWebResponse() {
return webResponse;
}
public void setWebResponse(String webResponse) {
this.webResponse = webResponse;
}}
您是否有任何线索为什么这两种方法都不起作用,尽管有教程? 提前谢谢。
答案 0 :(得分:0)
你可以使用ksoap library.refer跟随url访问soap web服务 http://code.tutsplus.com/tutorials/consuming-web-services-with-ksoap--mobile-21242