Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I've spent a few months trying to grasp the concepts behind WCF and recently I've developed my first WCF service application.
I've struggled quite a bit to understand all the settings in the config file.
I am not convinced about the environment but it seems that you can do amazing stuff with it.
The other day I've found out that Microsoft has come out with a new thing called ASP.NET Web API.
For what I can read it's a RESTful framework, very easy to use and implement.
Now, I am trying to figure out what are the main differences between the 2 frameworks and if I should try and convert my old WCF service application with the new API.

Could someone, please, help me to understand the differences and usage of each?

share|improve this question
9  
+1 interesting question. maybe you'll get good responses at programmers.stackexchange.com – Mithir Feb 19 '12 at 11:34
    
Which features of the "old" WCF are you using? Are you trying to build a RESTful API? Or RPC, or SOAP? – marcind Feb 19 '12 at 19:23
    
@marcind: thanks for your answer. It's mostly RESTful calls. No RPC at all. – LeftyX Feb 19 '12 at 19:26
3  
Another good answer can be found at stackoverflow.com/a/9859981/456814 – user456814 Dec 8 '12 at 6:22
    
both are one and the same thing but the old difference that one could come across would be the wcf is basically for intranet and Webapi for internet , yes definitely we can make wcf restful too! basically both has run upon the http protocol web.http – LostCoder Jan 7 '16 at 13:06
up vote 118 down vote accepted

The new ASP.NET Web API is a continuation of the previous WCF Web API project (although some of the concepts have changed).

WCF was originally created to enable SOAP-based services. For simpler RESTful or RPCish services (think clients like jQuery) ASP.NET Web API should be good choice.

share|improve this answer
14  
Also: Although WCF provides some support for writing REST-style services, the support for REST in ASP.NET Web API is more complete and all future REST feature improvements will be made in ASP.NET Web API msdn.microsoft.com/en-us/library/jj823172.aspx – Ohad Schneider Aug 3 '14 at 21:18
1  
Actually WCF was originally created to implement an abstraction layer between a SOAP or RPC service and the client. The point was to create a single architecture (ABC) around both these very different calls and handle the plumbing via configuration files. – Scott Marcus Nov 30 '15 at 14:52

For us, WCF is used for SOAP and Web API for REST. I wish Web API supported SOAP too. We are not using advanced features of WCF. Here is comparison from MSDN:

enter image description here

share|improve this answer
    
And Web API supports OData which for CSOM is a Godsend. – jmb.mage Nov 9 '15 at 16:22
4  
Its amazing how MS with so much says nothing really worthy. For example, WCF supports JSON but this information is well hidden in this "comparison", while it says textually that WebApi supports JSON not once but twice. – magallanes Mar 4 '16 at 12:36

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.

share|improve this answer

In the scenarios listed below you should go for WCF:

  1. If you need to send data on protocols like TCP, MSMQ or MIME
  2. If the consuming client just knows how to consume SOAP messages

WEB API is a framework for developing RESTful/HTTP services.

There are so many clients that do not understand SOAP like Browsers, HTML5, in those cases WEB APIs are a good choice.

HTTP services header specifies how to secure service, how to cache the information, type of the message body and HTTP body can specify any type of content like HTML not just XML as SOAP services.

share|improve this answer
    
simple enough.. – ebram khalil Sep 29 '14 at 14:52
3  
This makes the assumption that WCF only handles SOAP messages, an incorrect assumption. You can expose REST endpoints on WCF services as well. I would modify it to say, if you are not going to use the features of WCF (see tridy's message) then Web API makes sense. – Mike Jan 10 '15 at 23:16
    
Yep WCF does Rest as well.. basically Web api is a subset of WCFs functionality which is appropriate if your doing simple CRUD style data apps. – user1496062 Apr 3 '15 at 21:14

WCF will give you so much of out the box, it's not even comparable to anything. Unless you want to do on your own implementation of (to name a few) authentication, authorization, encryption, queuing, throttling, reliable messaging, logging, sessions and so on. WCF is not [only] web services; WCF is a development platform for SOA.

share|improve this answer
5  
If I'm not mistaken, I think that WEB API also provides most of the functions you listed. – Alex Mar 26 '15 at 8:45
1  
No Web api does not provide these things or provides very simple versions. – user1496062 Apr 3 '15 at 21:12
    
Well what is it - does it provide them or not? – JᴀʏMᴇᴇ Sep 6 '15 at 13:13
3  
For authentication and authorization, check asp.net/web-api/overview/security/…. tl;dr: It supports it definitely in IIS. For encryption, you'll probably need to use SSL, ASP.NET naturally handles queuing (but that's straight up based on worker threads available vs incoming requests). Sessions exist (but I'd never recommend using Sessions directly). Logging is easy enough to set up (through ActionFilters or the such). An alternative to reliable messaging is using SignalR (although not exactly). – James Haug Oct 10 '15 at 19:53
2  
"Not comparable to anything"?? Unlikely. – user1585345 Feb 5 '16 at 15:51

Business speaking, WebApi lacks of a WSDL, so the developers should document all manually. And if, for example, the WebApi operation returns a list of objects then, the client should creates the objects manually, i.e. WebAPI is really prone to errors of definitions.

The pro of Webapi is its more lightweight than WCF.

share|improve this answer
    
WCF == WS-*, webapi == REST – BozoJoe Jun 23 '16 at 4:49

Regarding the statement "WebApi lacks of WSDL" there are several ways to generate Rest client. One popular approach is Swagger UI / (Swashbukkle Nuget). This gives a rich interface to understand the REST end point's input and output schema and online tool to test the end points.

JSON LD (Json Linked Documents) is another emerging standard which will further improve the JSON based REST developer experience by exposing the JSON schema with better semantics.

share|improve this answer

Since using both till now, I found many differnce between WCF and WEB Api.Both technologies stack suited well in different- differet scenario.So It is not possible to say which is more better, this depends on configuration and scenario.

See this image to understand more differnce

Note: The data is not only my view this is also collected from other official website.

share|improve this answer

protected by Community Dec 18 '15 at 12:07

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.