Recently I was asked multiple questions about WCF, Web API, actually I posted multiple blog articles which were about WCF, Web API, The relationships between WCF, WCF Web API and ASP.NET Web API etc. in 2010 ~ 2013. Let me review them first, and then I will add new content and changes
My Existing Blogs which were about WCF and ASP Web API
Let me try to add more information about WCF and Web API (What I said Web API mostly mean ASP.NET Web API)
What is WCF and What is ASP.NET Web API ?
WCF: Windows Communication Foundation.
WCF is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data.
(From Microsoft website)
ASP.NET Web API:
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
(From Microsoft website)
WCF vs ASP.NET Web API ?
Actually we can not compare WCF and ASP.NET Web API directly since they are really different things, WCF had a part before which was WCF Web API, it was similar with current ASP.NET Web API, I have had blog mentioned WCF Web API was merged to ASP.NET Web API;
So now there are 2 different concepts: WCF and ASP.NET Web API.
Actually in our Visual Studio 2013 and 2015, we can see Microsoft really separates WCF and ASP.NET Web API (which is under the Web template) in the project templates:
- When we should use WCF, When we should use ASP.NET Web API ?
I have gave good answers in my old blog "More about WCF and Web API", There also have been lots of other resources and websites gave the answer already, let me collect some information here again:
1: WCF Web API was not enough to support Web API; We used WebHttpBinding to support Web API in WCF before; but now, if you want to use Web API, you maybe have to use the new tech called ASP.NET Web API without WCF, because the new ASP.NET has more features that supports Web API;
2: WCF mainly provides SOAP services, WCF WebHttpBinding provides non-SOAP service over HTTP (called RESTful services), the new Web API provides HTTP Services (Only);
3: WCF can build services to support not only HTTP, but also TCP, UDP, Message Queue, Name Pipe and other custom transports; ASP.NET Web API ONLY supports HTTP;
4: WCF services support multiple encodings such as Text, Binary, Soap XML, ASP.NET Web API support XML, JSON
5: ASP.NET Web API can implement much more complete RESTful services than WCF;
check Microsoft official website to read more details information.
- Compare using Real cases:
Let me show part of code from my real applications, hope we can see some differences between WCF and ASP.NET Web API.
One of our old WCF application, we can see we have Data Contract and Data Members in a Service
We also had Operation Contract in Service interface and implemented then for each one:
In Web Terminal, we use Service Client to load the Server side services:
Let’s see ASP.NET Web API, I will use the ASP.NET official site samples to show the differences:
The following is the sample code on the server side, which shows how the web services are:
I only wan to give above content for this blog article, there are more information for comparing WCF and ASP.NET Web API actually, please search information by yourself. Thanks for your reading and visiting my blog site.