2

Android アプリを開発していますが、いくつかの Web サービス参照をインポートする必要があります。現在、私はEclipse Indigoを使用していますが、Web 参照のインポート オプションが見つかりませんでした。

4

2 に答える 2

1

私の知る限り、Android で WSDL サービス参照を自動的に作成する方法はありません。

残念ながら、WSDL サービスにアクセスするクラスとメソッドを自分で定義する必要があります。

Web サービスが SOAP を使用している場合は、サービスの呼び出しを支援するライブラリとしてhttp://code.google.com/p/ksoap2-android/を調査することをお勧めします。

于 2011-09-28T03:45:48.927 に答える
1

java.io.BufferedReader をインポートします。java.io.InputStream をインポートします。java.io.InputStreamReader をインポートします。import 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);
}

}

DB サービスの URL アドレスを置き換えます。それを呼び出し、結果として文字列を受け取ります...

于 2011-09-28T04:33:10.753 に答える