【问题标题】:How to import web service reference in Android by using Eclipse Indigo?如何使用 Eclipse Indigo 在 Android 中导入 Web 服务引用?
【发布时间】:2011-09-26 05:30:49
【问题描述】:

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

【问题讨论】:

  • 网络服务参考??
  • 需要更多关于这个问题的信息,我什至不知道你所说的“网络服务引用”是什么意思?
  • 好的,我有一个服务 url(.net web 服务),我需要将这些 url 导入到我的项目中,我需要使用这些服务 url 中的类和方法。

标签: android wcf web-services eclipse-indigo


【解决方案1】:

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

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

如果您的 Web 服务使用 SOAP,那么您可能希望将 http://code.google.com/p/ksoap2-android/ 作为一个库来帮助您进行服务调用。

【讨论】:

  • 不是 WCF 正在使用 Web 服务
  • 好吧,也许您正在使用一种支持 WSDL(Web 服务描述语言)的较旧的 .net 技术。无论哪种方式,我都不相信有任何可用的 Eclipse 扩展可以读取 WSDL 并为您创建服务引用/类。
  • 是的,目前我已经使用了axis2java jar 文件,并且我得到了“导入网络参考”之类的选项,但是在这个靛蓝版本中它对我不起作用会出错吗?那么有没有其他方法可以做到这一点?
【解决方案2】:

导入 java.io.BufferedReader; 导入 java.io.InputStream; 导入 java.io.InputStreamReader; 导入 java.util.ArrayList;

导入 org.apache.http.HttpEntity; 导入 org.apache.http.HttpResponse; 导入 org.apache.http.NameValuePair; 导入 org.apache.http.client.HttpClient; 导入 org.apache.http.client.entity.UrlEncodedFormEntity; 导入 org.apache.http.client.methods.HttpPost; 导入 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 地址。它会调用它并接收字符串作为结果......

【讨论】:

  • 在我的服务 url 中我有这么多的类和方法,那么我如何在 android 应用程序中使用它们?
  • 在您的活动中创建上述类的实例,并通过传递 httpPost 对列表来调用其函数,如果您想发布一些可以在网络服务中读取的数据。这样做: DBService dbservice = new DBService(); dbsesservice.sendDBRequest(httpPost);
猜你喜欢
  • 2012-04-30
  • 2012-11-19
  • 1970-01-01
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 2012-03-01
相关资源
最近更新 更多