9

I'm about to start a project where we have a back-end service to do long-winded processing so that our ASP.NET website is free to do quicker requests. As a result I have been reading up on services such as WCF and Web API to get a feel for what they do. Since this back-end service will actually be made up of several services communicating to each other and will not be publicly available to our customers, it seems that WCF is the ideal technology for this kind of scenario.

But after doing a lot of research I am still confused as to the benefits and differences between WCF and Web API. In general it seems that:

  • If you want a public and/or a RESTful API then Web API is best
  • WCF can support far more transports than just HTTP so you can have far more control over them
  • Web API development seems easier than WCF due to the additional features/complexity of WCF

But perhaps my question boils down to the following:

  1. Why would a REST service be more beneficial anyway? Would a full blown WCF service ever be a good idea for a public API? Or is there anything that a WCF service could provide that Web API cannot?
  2. Conversely, if I have a number of internal services that need to communicate with each other and would be happy to just use HTTP as the transport, does Web API suddenly become a viable option?
Steven
  • 166,672
  • 24
  • 332
  • 435
Peter Monks
  • 4,219
  • 2
  • 22
  • 38

3 Answers3

10

I answered a couple of related questions:

As an additional resource, I would like to recommend you to read:

http://www.codeproject.com/Articles/341414/WCF-or-ASP-NET-Web-APIs-My-two-cents-on-the-subjec

If you want to learn more about REST, check this Martin Fowler article

Summaring up:

As far as I know, both technologies are being developed by the same team in Microsoft, WCF won't be discontinued, it will still be an option (for example, if you want to increase the performance of your services, you could expose them through TCP or Named Pipes). The future is clearly Web API

  • WCF is built to work with SOAP

  • Web API is built to work with HTTP

In order to take the correct choice:

  • If your intention is to create services that support special scenarios – one way messaging, message queues, duplex communication etc, then you’re better of picking WCF
  • If you want to create services that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transports are unavailable, then you’re better off with WCF and using both SOAP-based bindings and the WebHttp binding.
  • If you want to create resource-oriented services over HTTP that can use the full features of HTTP – define cache control for browsers, versioning and concurrency using ETags, pass various content types such as images, documents, HTML pages etc., use URI templates to include Task URIs in your responses, then the new Web APIs are the best choice for you.
  • If you want to create a multi-target service that can be used as both resource-oriented service over HTTP and as RPC-style SOAP service over TCP – talk to me first, so I’ll give you some pointers.
Community
  • 1
  • 1
Jupaol
  • 21,107
  • 8
  • 68
  • 100
  • WCF also supports RESTful services, though. So saying "WCF is built for SOAP" seems incorrect IMO. – Josh M. Jul 15 '13 at 12:39
  • 1
    @JoshM. - Yes, but "the support for REST in ASP.NET Web API is more complete" as this [msdn article](https://msdn.microsoft.com/en-us/library/jj823172.aspx) states. – BornToCode Jan 25 '15 at 13:17
1

One combersome bit of WCF is the need to generate new client proxys when input and/or output models change in the service. REST services don't require proxys, the client simply changes the query string sent or changes to parse and/or use the different output.

I found the default JSON serializers in .Net to be a bit slow, I implemented http://json.codeplex.com/ to do the inbound and output serialzation.

WCF services are not that complex, REST services can be equally challenging as you're working within the confines of HTTP.

lcryder
  • 486
  • 2
  • 8
0

ASP.net Web API is all about HTTP and REST based GET,POST,PUT,DELETE with well know ASP.net MVC style of programming and JSON returnable; web API is for all the light weight process and pure HTTP based components. For one to go ahead with WCF even for simple or simplest single web service it will bring all the extra baggage. For light weight simple service for ajax or dynamic calls always WebApi just solves the need. This neatly complements or helps in parallel to the ASP.net MVC. Check out the podcast : Hanselminutes Podcast 264 - This is not your father's WCF - All about the WebAPI with Glenn Block by Scott Hanselman for more information.

Community
  • 1
  • 1
Naveen Vijay
  • 15,928
  • 7
  • 71
  • 92