C# – WCF Service or Web API

asp.netasp.net-mvcasp.net-web-apicwcf

I'm going to be working on a project that involves a number of elements:

  • ASP.NET MVC website
  • C# console application
  • iPhone App

To get all these separate applications talking to the database, my immediate thought was to use a WCF Service.

However, I now need to add an API to the site to allow third parties to select, insert and update records from their own applications.

In my mind, I would just create a separate RESTful service endpoint on my WCF Service which would be locked down using authentication and would only give access to certain methods.

However, I've been reading today about the Web API feature in MVC 4 which is meant to be the latest thing for RESTful APIs?

Should I be going along the line of using the Web API? or because my other applications need a web service, should I stick with a WCF Service?

Best Answer

If you intend to do RESTful development then you will definitely want to use the ASP.Net Web Api (which was originally called WCF Web Api and created with the goal of "Making REST a first class citizen in .NET".

Another thing to consider is that the WCF REST Starter kit is no longer supported.

Note that using Web Api doesn't mean you have to use ASP.Net MVC or IIS even as it can be self hosted.

For handling operations which are non-CRUD in nature I'd recommend Googling "REST non-CRUD". I found this blog post RESTful URLs for non-CRUD operations (and particularly the comments interesting). If you decide you NEED to have RPC calls then those may have to be done with WCF. That said since WCF REST is being killed off I'm not sure what the best solution is going to be. Having both is probably the best answer but at the same time it's not necessarily a good answer.

Another alternative would be a WCF OData Service but I'm not sure if that gets any support from an iPhone.

One last point to make (that can be deleted in the future as this is time sensitive)

Microsoft has provided a Go Live license with the beta which means that it is supported by Microsoft and you shouldn't have any problems upgrading to the file RTM.