简体   繁体   中英

android - cannot access soap web service

I'm trying to create an android application which could be able to access a Web Service.
I used the example provided on this website: http://codeoncloud.blogspot.fr/2013/06/android-java-soap-web-service-access.html (part 1).
However it doesn't work at all, it keeps displaying "1 USD = LKR" instead of "1 USD = 128.95 LKR". And yet, this code uses threads (because after much research, I found out that network requests need to be done on background thread after Android 3.0).

I've also tried to create an AsyncTask but it doesn't work either.
Here is an example of my code below:
RetrieveFeedTask (my 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;
}}

Do you have any clue why these both methods don't work despite the tutorials? Thanks in advance.

您可以使用kso​​ap库访问肥皂网络服务。请参考以下网址http://code.tutsplus.com/tutorials/consumption-web-services-with-ksoap--mobile-21242

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM