简体   繁体   English

Android Rest Asp.net Web服务?

[英]Android Rest Asp.net Web Services?

I am new on android, i want to use asp.net webservices in my android app. 我是android的新手,我想在我的android应用中使用asp.net webservices。 but i dont know how i can use this?. 但我不知道该怎么用?

i want to do with Restful method.But when i search in google, i found all tutorials in soap. 我想使用Restful method.But,但是当我在google中搜索时,我发现了所有使用Soap的教程。 Is soap is compulsory for asp.net or there is ant other option available that we can use rest for asp.net in android. 是对asp.net强制使用肥皂还是有其他可用选项,我们可以在android中对asp.net使用其余选项。

i have follow this tutorials. 我已经按照本教程。 link 链接

You can always use JSON. 您可以随时使用JSON。

Json is the fastest data transfer mode across network, so your webservice should return data in Json format. Json是跨网络最快的数据传输模式,因此您的Web服务应以Json格式返回数据。

Once you have Json you can always render it and use it as needed. 一旦有了Json,您就可以随时对其进行渲染并根据需要使用它。

Here is example to render data http://www.tutorialspoint.com/android/android_json_parser.htm 这是呈现数据的示例http://www.tutorialspoint.com/android/android_android_json_parser.htm

You can create a WCF REST web service 您可以创建WCF REST Web服务

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

or an easier way is to create a new MVC4 web application, and update your Controller to extend Api Controller, then create a new web method that will return a HttpResponseMessasge like so: 或更简单的方法是创建一个新的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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM