开发者

How to import web service reference in Android by using Eclipse Indigo?

开发者 https://www.devze.com 2023-04-08 21:17 出处:网络
I\'m developing an android app and I have to import some web service references; currently I\'m using Eclipse Indigo and I didn\'t find any import web re开发者_C百科ference option, so can anyone help

I'm developing an android app and I have to import some web service references; currently I'm using Eclipse Indigo and I didn't find any import web re开发者_C百科ference option, so can anyone help me how to do it?


As far as I am aware there isn't any method of automatically creating WSDL service references in Android.

Unfortunately you will need to define the classes and methods that access the WSDL services yourself.

If your web service is using SOAP then you may want to investigate http://code.google.com/p/ksoap2-android/ as a library to assist you with making the service calls.


import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList;

import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient;

public class DbRequest {

public DbRequest() {
}
public String sendDBRequest(ArrayList<NameValuePair> httpPost) {
    String result = "";

    String url = "http://www.YourURL.com/android/dbservice.php";//For Online Server
    //String url = "http://10.0.2.2/android/dbservice.php";
    //String url = "http://192.168.1.4/android/dbservice.php";//For Local Server
    InputStream is = null;

    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        httppost.setEntity(new UrlEncodedFormEntity(httpPost));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    } catch (Exception e) {
        result = e.toString();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
    } catch (Exception e) {

        result = e.toString();
    }
    return (result);
}

}

Replace the URL Address of your DB Service. It'll call it and will receive string as a result...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号