从android eclipse消耗webservice [英] consuming webservice from android eclipse

查看:116
本文介绍了从android eclipse消耗webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是纯粹的初学者[android-eclipse],这里我需要从网址http://122.248.240.105:93通过android eclipse消费Web服务,所以
请列出消费者的步骤web服务,如果可能,我发送演示作为任何一个web服务从该url或其他一些例子。

I am pure beginner to [android-eclipse],here i need to consume web services from the url "http://122.248.240.105:93" through android eclipse so please list the steps to consume the web services, if possible send me demo as any one web service from that url or some other examples.

非常感谢

推荐答案

你可以很容易地消费安逸的服务。
和数据交换更喜欢json而不是XML。
i我从Android客户端附带了一个安静的服务调用示例。

you can consume restful services very easily. and for data exchange prefer json rather than XML. i am attaching one sample of restful service call from android client with JSON.

  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; 
    }
    }

    }

我有使用了休息的WCF并在我的代码中使用了Json。
您可以使用此作为使用json的简单服务的模板。
为了休息的服务。

I have used restful WCF and used Json in my code. you can use this as template for restful services with json. for restful services.

我喜欢安静的json,但如果你想阅读关于ksoap教程,我建议你阅读:
http://www.devx.com/wireless/Article/39810/1954
如何使用kso​​ap2调用WCF服务android?

i would prefer restful with json but if you want to read about ksoap tutorials i suggest you to read: http://www.devx.com/wireless/Article/39810/1954 How to call a WCF service using ksoap2 on android?

webservices:
http://sochinda.wordpress.com/2011/05/27/connecting-to-net-web-service-from-android/
http://android.vexedlogic.com/zh-cn/ >

webservices: 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:

saxparser:

< a href =http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html =nofollow noreferrer> 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

Drawables pics: http://androiddrawableexplorer.appspot.com/

Drawables pics: http://androiddrawableexplorer.appspot.com/

如果对您有帮助,请接受答案。谢谢

Please accept the answer if it is helpful for you. thanks

这篇关于从android eclipse消耗webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆