简体   繁体   English

如何在asp.net中创建RESTful Web服务?

[英]How to create a RESTful web service in asp.net?

I simply want to create a fairly basic REST service, so that I can expose some of the data in my asp.net/SQL server application to the outside works, like this..... 我只是想创建一个相当基本的REST服务,这样我就可以将我的asp.net/SQL服务器应用程序中的一些数据暴露给外部工作,就像这样......

http://domain.com/api/offices - would return an xml set of office locations. http://domain.com/api/offices - 将返回一组xml的办公地点。 http://domain.com/api/offices/15 - would return all the details of office 15. http://domain.com/api/offices/15 - 将返回办公室15的所有细节。

It's all fairly standard stuff (including basic authentication) but there seem to be several ways to achieve this using Microsoft technologies and I don't really know where to start. 这些都是相当标准的东西(包括基本身份验证),但似乎有几种方法可以使用Microsoft技术实现这一点,我真的不知道从哪里开始。 These seem to be the options... 这似乎是选择......

1) WCF 1)WCF

2) ASP.NET MVC 2)ASP.NET MVC

3) ADO.NET Data Services 3)ADO.NET数据服务

4) Rest Starter Kit project templates? 4)Rest Starter Kit项目模板?

Which of these is the easiest and most "up-to-date" solution to creating a web service? 哪些是创建Web服务最简单,最“最新”的解决方案?

If you don't plan on adding any other endpoints in the future (like SOAP, etc.) and the Service isn't going to be consumed by a Silverlight client, I would suggest using ASP.NET MVC. 如果您不打算将来添加任何其他端点(如SOAP等),并且Silverlight客户端不会使用该服务,我建议使用ASP.NET MVC。

If Silverlight is involved, then use ADO.NET Data Services. 如果涉及Silverlight,则使用ADO.NET数据服务。

If you plan on building out a robust Service framework with multiple endpoint types, then use WCF. 如果您计划构建具有多个端点类型的强大服务框架,那么请使用WCF。

There are a few alternatives, not sure if you heard of them but might as well look into them: 有一些选择,不确定你是否听说过它们,但不妨看看它们:

  • Open Rasta IT sa fairly opinionated Rest framework that lets you create web services and web sites, its a bit weird to get your head around it first but; 打开Rasta IT是一个相当自以为是的Rest框架,可以让你创建Web服务和网站,它有点奇怪,首先要了解它; its so light weight that makes sense to give it a go, it requires some idea on how Rest actually works (and not the .net abstraction that you might be used to) and i think it doesnt have a very strong dependency on asp.net, an obvious advantage to me is that you can encode to HTML, JSON or any format you might need, its quite interesting 它的重量很轻,有理由给它一个去,它需要一些关于Rest实际如何工作的想法(而不是你可能习惯的.net抽象),我认为它对asp.net没有很强的依赖性。 ,对我来说一个明显的优势是你可以编码为HTML,JSON或你可能需要的任何格式,它非常有趣

  • Another option out there, (that I havent used), is Siesta , wich works on top of Asp.net mvc 另一种选择(我没用过)是Siesta ,它在Asp.net mvc上工作

Wcf configuration can get very painful very quickly... Wcf配置很快就会非常痛苦......

Hope it helps 希望能帮助到你

ADO.NET Data Services is now WCF Data Services, and that's what I'd recommend. ADO.NET数据服务现在是WCF数据服务,这就是我推荐的。 It's pretty easy to work with (at least for the type of services you describe). 它很容易使用(至少对于您描述的服务类型)。 You might also want to take a look at the Open Data Protocol -- you probably don't need it, unless you're supporting non-.NET clients (PHP, Java). 您可能还想查看开放数据协议 - 您可能不需要它,除非您支持非.NET客户端(PHP,Java)。

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

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