我是純粹的初學者到[android-eclipse],在這裏我需要通過android eclipse從url「http://122.248.240.105:93」使用web服務,所以 請列出步驟使用Web服務,如果可能的話,請將演示作爲來自該URL或任何其他示例的任何一種Web服務。從android eclipse消費webservice
非常感謝
我是純粹的初學者到[android-eclipse],在這裏我需要通過android eclipse從url「http://122.248.240.105:93」使用web服務,所以 請列出步驟使用Web服務,如果可能的話,請將演示作爲來自該URL或任何其他示例的任何一種Web服務。從android eclipse消費webservice
非常感謝
可以非常方便的消費RESTful服務。 和數據交換偏好json而不是XML。 我從JSON附加一個來自Android客戶端的寧靜服務調用示例。
public class LoginService {
loginurl="http:/yourhostname.com/Service.svc/Service/ValidateMobileUser";
/**
* This method is used to validate client name from wcf
*
* @param 1: username
* @param 2: password *
* @return true or false as string value
*/
public String authenticate(String userName, String passWord
) throws JSONException, IllegalStateException,
IOException,NullPointerException {
Log.d("input authenticate method", userName + passWord);
HttpPost request = new HttpPost(loginurl);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
JSONObject json = new JSONObject();
json.put("UserName", userName);
json.put("Password", passWord);
json.toString();
JSONStringer str = new JSONStringer().object().key("clientEntity")
.value(json).endObject();
StringEntity entity = new StringEntity(str.toString());
request.setEntity(entity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
Log.e("Status code ", "status code is " + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
char[] buffer = new char[(int) responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
String response_str = new String(buffer);
int i = response.getStatusLine().getStatusCode();
if (i == 200) {
Log.d("output authenticate method", response_str);
return response_str;
} else {
response_str = Integer.toString(i);
return response_str;
}
}
}
我已經使用了restful WCF並在我的代碼中使用了Json。 你可以使用它作爲json平靜服務的模板。 以享受寧靜的服務。
我寧願寧靜的使用JSON,但如果你想了解KSOAP教程我建議你閱讀: http://www.devx.com/wireless/Article/39810/1954 How to call a WCF service using ksoap2 on android?
web服務: http://sochinda.wordpress.com/2011/05/27/connecting-to-net-web-service-from-android/ http://android.vexedlogic.com/2011/04/17/android-lists-iv-accessing-and-consuming-a-soap-web-service-i/
的SAXParser:
http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html
kshop: http://seesharpgears.blogspot.com/2010/11/returning-array-of-primitive-types-with.html
http://seesharpgears.blogspot.com/2010/11/basic-ksoap-android-tutorial.html
可繪製圖片:http://androiddrawableexplorer.appspot.com/
請接受的答案,如果它是對你有幫助。謝謝
你想要消耗哪種類型的服務? – 2012-03-16 07:33:59
SOAP還是RESTful webservice? – 2012-03-16 08:49:50