【问题标题】:consuming webservice from android eclipse [closed]从android eclipse消费webservice [关闭]
【发布时间】:2013-04-02 12:17:02
【问题描述】:

我是 [android-eclipse] 的纯初学者,这里我需要通过 android eclipse 从 url "http://122.248.240.105:93" 使用 web 服务所以 请列出使用 Web 服务的步骤,如果可能的话,将演示作为来自该 URL 的任何一项 Web 服务或其他示例发送给我。

非常感谢

【问题讨论】:

  • 您想使用哪种类型的服务?

标签: android eclipse web-services


【解决方案1】:

您可以非常轻松地使用宁静的服务。 对于数据交换,更喜欢 json 而不是 XML。 我正在附加一个来自带有 JSON 的 android 客户端的 restful 服务调用示例。

  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 的 restful 服务的模板。 享受宁静的服务。

我更喜欢 json 的宁静,但如果你想阅读 ksoap 教程,我建议你阅读: http://www.devx.com/wireless/Article/39810/1954 How to call a WCF service using ksoap2 on android?

网络服务: 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/

如果对您有帮助,请采纳答案。谢谢

【讨论】:

    猜你喜欢
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 2019-03-10
    • 1970-01-01
    相关资源
    最近更新 更多