如何使用Eclipse Indigo在Android中导入Web服务引用?

时间:2011-09-26 05:30:49

标签: android wcf web-services eclipse-indigo

我正在开发一个Android应用程序,我必须导入一些Web服务引用;目前我正在使用 Eclipse Indigo ,我没有找到任何导入网络参考选项,所以有人可以帮我怎么做吗?

2 个答案:

答案 0 :(得分:1)

据我所知,没有任何方法可以在Android中自动创建WSDL服务引用。

不幸的是,您需要自己定义访问WSDL服务的类和方法。

如果您的网络服务使用的是SOAP,那么您可能需要将http://code.google.com/p/ksoap2-android/调查为图书馆,以协助您拨打服务电话。

答案 1 :(得分:1)

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;

公共课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);
}

}

替换数据库服务的URL地址。它会调用它并因此会收到字符串......