安卓Rest Asp.net网络服务

本文关键字:网络服务 net Asp Rest 安卓 | 更新日期: 2023-09-27 17:59:14

我是安卓系统的新手,我想在我的安卓应用程序中使用asp.net Web服务。但是我不知道该怎么用?。

我想用Restful方法。但当我在谷歌上搜索时,我在soap中找到了所有教程。对于asp.net,soap是强制性的吗?或者还有其他选项,我们可以在android中为asp.net使用rest。

我已经遵循了这个教程。链接

安卓Rest Asp.net网络服务

您可以始终使用JSON。

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

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

以下是渲染数据的示例http://www.tutorialspoint.com/android/android_json_parser.htm

您可以创建WCF REST web服务

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

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

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