我正在開發一個android應用程序,我必須導入一些web服務引用;目前我正在使用Eclipse Indigo,我沒有找到任何導入Web參考選項,所以任何人都可以幫助我如何做到這一點?如何使用Eclipse Indigo在Android中導入Web服務引用?
回答
據我所知,在Android中沒有任何自動創建WSDL服務引用的方法。
不幸的是,您需要定義自己訪問WSDL服務的類和方法。
如果您的Web服務使用SOAP,那麼您可能需要調查http://code.google.com/p/ksoap2-android/作爲庫來協助您進行服務調用。
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地址。它會調用它,並將收到字符串作爲結果...
在我的服務網址中,我有很多類和方法,所以如何在Android應用程序中使用它們? – nag
在您的活動中創建上述類的實例,並通過傳遞httpPost對列表來調用其功能,如果您想發佈一些可以在web服務中讀取的數據。這樣做: DBService dbservice = new DBService dbsesrvice.sendDBRequest(httpPost); –
- 1. 如何使用Eclipse Indigo在Tomcat7中部署Web應用程序?
- 2. Applet Web服務客戶端,使用Apache CXF的Eclipse Indigo,
- 3. 如何在Android中使用Web服務?
- 4. 如何在Android中使用Web服務?
- 5. 在Eclipse Indigo中使用VisualVM
- 6. 如何使用eclipse調試Web服務
- 7. android/eclipse中的web服務
- 8. 引用Ashx Web服務 - 使用Web還是服務引用?
- 9. 如何在Android中調用Web服務
- 10. 如何在android中調用web服務
- 11. 如何在android中調用web服務
- 12. 添加web服務引用到eclipse
- 13. 如何在Eclipse中爲WCF服務「添加服務引用」?
- 14. Android使用Eclipse Indigo Service Release 2編程
- 15. 如何使用eclipse在juddiv3中發佈Web服務
- 16. 如何使用eclipse在java中創建Web服務
- 17. 如何發佈使用Eclipse在Java中創建的Web服務?
- 18. 如何在Visual Studio 2012中使用引用的Web服務
- 19. 如何使用Indigo設置Eclipse PDE/Build?
- 20. 導入任務在android eclipse
- 21. 如何在Web服務中維護集合類型(使用Web引用而非服務引用)
- 22. 如何在python中使用https服務使用web服務
- 23. 在android中使用web服務
- 24. 在Android中使用Web服務
- 25. 在android中使用JSON Web服務
- 26. 在Android中使用Web服務
- 27. 在Android中使用.net web服務
- 28. 在Android中使用XML-RPC Web服務
- 29. 在Android中使用Web http服務
- 30. 無法在Eclipse Indigo中使用Google SVN
Web服務引用? –
ya服務參考。 – nag
在這個問題上需要更多的信息,我甚至不知道你的意思是「網絡服務引用」? –