25

What is the advantage of using new WCF Web API over ASP.NET MVC 3 to expose a lightweight JSON Web service layer? I like Web API in many ways, but the drawback is that it doesnt work on mono, while MVC 3 does. What are the major differences between the two approaches?

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
adrin
  • 3,738
  • 8
  • 40
  • 60
  • possible duplicate of [What is the best way to implement a RESTful architecture in .NET today?](http://stackoverflow.com/questions/4318196/what-is-the-best-way-to-implement-a-restful-architecture-in-net-today) – Darin Dimitrov May 01 '11 at 11:30
  • 3
    Have you listened to the recent Hanselminutes with Glenn Block? This topic is discussed at length. http://www.hanselman.com/blog/HanselminutesPodcast264ThisIsNotYourFathersWCFAllAboutTheWebAPIWithGlennBlock.aspx – Darrel Miller May 01 '11 at 12:20

4 Answers4

8

It is recognized by Microsoft, that there is some overlap between the two products. However, they do have a different focus:

  • If you are building a web site that consumes JSON from your web service then MVC is probably the best choice.

  • If you are building an API intended to be consumed by a variety of third party clients then WCF Web API is the best choice.

My own personal reasons include the fact that with WCF Web API means I can self-host in a Windows service, and I can avoid ASP.NET, web.config and Cassini :-)

Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • The reason for this is that you can expose other formats/endpoints than HTTP/JSON? Glen Block mentioned also that WCF Web API is more intended for customers already heaving their service layer written in WCF. – adrin May 01 '11 at 12:33
  • @adrin You "can" expose other formats in ASP.NET MVC, it's just not a primary goal of ASP.NET MVC, whereas it is a primary goal of WCF Web API. It's really just an issue of focus. – Darrel Miller May 01 '11 at 12:36
  • @adrin Sure, if you are already familiar with WCF, then it will be and easier transition. The new bits retain a lot of backward compatibility with WCF REST 3.5 and 4. – Darrel Miller May 01 '11 at 12:39
  • I see you posting a lot on REST here at SO. Can you please throw some light on OpenRasta if you have looked at it? Like what is the current state of the project and how is it for creating RESTful service on .NET stack? – IsmailS Jun 03 '11 at 12:24
  • @Ismail I have only looked at OpenRasta a bit but @Serialseb knows what he is doing and is extremely smart. OpenRasta is opinionated and if those opinions match yours, then it will be awesome. If they don't you then you will have to look under the covers as it is very configurable. However, you will have a reasonable learning curve to be able to change its default opinions. – Darrel Miller Jun 03 '11 at 13:11
3

Updated 6/24/14 by request:

What is now ASP.NET Web API (formerly WCF Web API) and ASP.NET MVC will formally merge in what is currently dubbed ASP.NET vNext (MVC 6).

http://www.asp.net/vnext/overview/aspnet-vnext/overview

===========================================================================

Original answer:

It was announced yesterday (2/8/2012) that the projects are formally merging. See:

http://www.c4mvc.net/meeting/?id=25

and

http://msdn.microsoft.com/en-us/hh824721

The c4mvc link should be updated with a link to Dan Roth's presentation soon.

David Peden
  • 17,596
  • 6
  • 52
  • 72
2

I believe this question targets new WCF Web API and because of that it is not the same as question linked as duplicate.

WCF Web API removes some limitations of current WCF Rest support but the main disadvantage of the Web API is that it is only a draft - currently preview 4. It has no support and probably it is not supposed to be used in production environment. Also any new version can introduce breaking changes or remove whole set of features available in previous version. Because of that you should use ASP.NET MVC to build lightweight JSON service layer.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
-4

The differences are night and day. MVC Framework is not a web service layer. If you truly need a web service to be consumed by varying clients (and possibly on varying platforms) then you are left to choose between a WCF-based web service or an old-fashioned XML web service.

Kon
  • 27,113
  • 11
  • 60
  • 86