English 中文(简体)
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.....

http://domain.com/api/offices - would return an xml set of office locations. http://domain.com/api/offices/15 - would return all the details of office 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. These seem to be the options...

1) WCF

2) ASP.NET MVC

3) ADO.NET Data Services

4) Rest Starter Kit project templates?

Which of these is the easiest and most "up-to-date" solution to creating a web service?

最佳回答

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.

If Silverlight is involved, then use ADO.NET Data Services.

If you plan on building out a robust Service framework with multiple endpoint types, then use WCF.

问题回答

There are a few alternatives, not sure if you heard of them but might as well look into them:

  • Open Rasta IT s a 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; 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

  • Another option out there, (that I havent used), is Siesta, wich works on top of Asp.net mvc

Wcf configuration can get very painful very quickly...

Hope it helps

ADO.NET Data Services is now WCF Data Services, and that s what I d recommend. 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).





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签