【问题标题】:Android Rest Asp.net Web Services?Android Rest Asp.net Web 服务?
【发布时间】:2014-04-21 11:15:52
【问题描述】:

我是 android 新手,我想在我的 android 应用程序中使用 asp.net webservices。 但我不知道如何使用它?。

我想使用 Restful 方法。但是当我在谷歌搜索时,我发现所有教程都在肥皂中。 肥皂对于 asp.net 是强制性的,还是有其他可用选项可供我们在 android 中为 asp.net 使用 rest。

我已按照本教程进行操作。link

【问题讨论】:

    标签: c# android asp.net web-services soap


    【解决方案1】:

    您始终可以使用 JSON。

    Json 是最快的网络数据传输模式,因此您的 Web 服务应该以 Json 格式返回数据。

    一旦你有了 Json,你就可以随时渲染它并根据需要使用它。

    这里是渲染数据的例子 http://www.tutorialspoint.com/android/android_json_parser.htm

    【讨论】:

      【解决方案2】:

      您可以创建 WCF REST Web 服务

      http://msdn.microsoft.com/en-us/library/ms731082(v=vs.110).aspx

      或者更简单的方法是创建一个新的 MVC4 Web 应用程序,并更新您的 Controller 以扩展 Api Controller,然后创建一个新的 Web 方法,该方法将返回一个 HttpResponseMessasge,如下所示:

      public class MyController : ApiController
      {
          public HttpResponseMessage MyWebMethod()
          {
              HttpContext.Current.Response.ContentType = "text/plain";
      
              HttpContext.Current.Response.Write([WRITE YOUR JSON HERE]);
      
              return new HttpResponseMessage(HttpStatusCode.OK);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-18
        • 2021-03-23
        • 2017-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多