使用asp.net mvc的基于REST端点 [英] using asp.net mvc for REST based endpoint

查看:108
本文介绍了使用asp.net mvc的基于REST端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待在使用ASP.Net MVC作为一个基于REST服务的平台。我知道WCF已经内置REST服务支持;不过,我期待在返回多个类型根据请求的数据。

I'm looking at using ASP.Net MVC as a platform for a REST based Service. I know WCF has built in support for REST services; however, I'm looking at returning multiple types of data depending on the request.

我想在客户端请求的内容类型。所以,如果他们发送的text / html比如我将使我的模型转换成HTML,如果他们要求的文本/ XML将返回XML。我们也可以做JSON。

I would like the client to request the content type. So if they send text/html for example I would render my model into Html, if they request text/xml it would return xml. We could also do JSON.

有谁看到任何与此问题?

Does anyone see any issues with this?

未使用WCF调用服务时,因为它们将不能够自动生成的代理可以增加客户的复杂性;然而,在我的情况下,客户将任一浏览器请求的HTML或Java客户端库处理XML。

Not using WCF could increase the complexity of the client when calling the service since they won't be able to auto-generate a proxy; however, in my case, the clients will be either browser requesting html, or java client libraries processing the xml.

由于没有使用WCF我们需要确保服务;但是,我想我们可以做到这一点使用窗体身份验证。

Since were not using WCF we need to secure the service; however, I'm thinking we can do this using forms authentication.

这样做的好处是,不管是什么类型的客户端请求它是所有经历同样的控制器/模型数据等......

The benefit of this is that no matter what type of data the client is requesting it is all going through the same controllers / models etc...

推荐答案

阅读哈克的帖子,关于使用扩展指示内容类型后,我想你最好键控关闭Accept头。似乎更Rest'ish对我来说,虽然其授予有点难度火浏览器并测试你的网址。

After reading Haack's post, about using extensions to indicate the content type, I think your better off keying off the Accept Header. Seems more Rest'ish to me, although granted its a little more difficult to fire up a browser and test your url.

我一起通过一个小博客文章中有关执行此操作,并使用ModelBinder的抽象出的HttpContext从你的控制器:的 http://jberke.blogspot.com/2009/03/aspnet-mvc-model-binder.html

I through together a little blog article about doing this and using a ModelBinder to abstract out the HttpContext from your controller: http://jberke.blogspot.com/2009/03/aspnet-mvc-model-binder.html.

此外回应特洛伊的选择在评论,我用的观点来呈现我的模型的XML。这让我有不同的XML格式相同的模型。这是有道理的。如果你需要支持的版本或不同的格式为不同的客户。我不喜欢自动渲染任何框架的想法。

Additionally in response to Troy's opt-in comment, I was using the view to render Xml of my model. This allowed me to have different xml formats for the same model. Which makes sense. What if you need to support versioning or different formats for different clients. I don't like the idea of the framework automatically rendering anything.

这篇关于使用asp.net mvc的基于REST端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆