【问题标题】:C# Rest web service and Android ClientC# Rest web 服务和 Android 客户端
【发布时间】:2009-07-28 09:47:53
【问题描述】:

嘿,我打算用 C# 和 android 客户端制作一个简单的 Rest web 服务。 我在此链接上找到了一个简单的 C# Web 服务,它添加了两个数字:

http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/RESTEnabledService05122009034907AM/RESTEnabledService.aspx

谁能帮我制作这个网络服务的安卓客户端

谢谢

【问题讨论】:

    标签: android web-services rest


    【解决方案1】:

    你可能发现了一些有用的东西,但我偶然发现了这个帖子,对于其他人来说,关注可能很有用。

    我更喜欢与 MVC 和 Android 一起使用的 REST 应用程序。 -www.asp.net/mvc(好的视频教程)

    创建服务器:

    h t t p:// omaralzabir.com/create_rest_api_using_asp_net_mvc_that_speaks_both_json_and_plain_xml/

    public class TestingController : Controller {
        /// <summary>
        /// Test
        /// </summary>
        /// <returns></returns>
        public ActionResult GetString() {
            return Content("A Result <orasxml id='testid'/>");
        }
    }
    

    并设置 Global.asax:

    //测试 routes.MapRoute("test", "{Page}.Mvc/tester", new { controller = "Testing", action = "GetString", Page = defaultPage });

    Andoid 客户端开发代码示例:

    http://www.smnirven.com/?p=15

    h t t p : //senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restful-client-at-android/

    公共字符串GetData(){

        //Note, do not use http:// in host name. I did not get localhost-adress working, but
        //hosted a page in IIS instead, and it worked.
        HttpHost target = new HttpHost("www.example,com",80);
        HttpGet get = new HttpGet("/tester");
        String result=null;
        HttpEntity entity = null;
        HttpClient client = new DefaultHttpClient();
        try {
            HttpResponse response=client.execute(target, get);
            entity = response.getEntity();
            result = EntityUtils.toString(entity);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        if (entity!=null)
        try {
            entity.consumeContent();
        } catch (IOException e) {}
        }
        return result;
    

    }

        //Display on buttontext, must create buttoon with ButtonReload as id...
        final Button btn = (Button) findViewById(R.id.ButtonReload);
        btn.setText(testString);
    

    关于为 Android 设计 REST 的提示:

    h t t p : //www.youtube.com/watch?v=xHXn3Kg2IQE

    h t t p : //www.infoq.com/articles/rest-introduction

    一般 Android 帮助:

    h t t p : //mobile.tutsplus.com/tutorials/android/introduction-to-android-development/

    h t t p : //www.youtube.com/watch?v=lqopIf-bA54&feature=related

    【讨论】:

      【解决方案2】:

      在这里查看我的问题:Unresolved Host Exception Android

      调用rest服务只是创建HttpResponse并处理返回的xml/json/value。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-14
        • 2014-09-04
        • 2016-02-19
        相关资源
        最近更新 更多