Thursday 3 September 2020

Difference between WCF and Web API ?

 Firsty We have to Understand What is WCF ? WCF stands for Windows Communication Foundation is also used for creating RestFul and Non Restful services like SOAP Services.WCF is mainly used for creating services that are protocol independent or transport independent. For example if we have a scenario in which we have two clients one is .NET client and other one is JAVA client and both the clients want to access a single WCF service with diffrent protocol and message formates like JAVA Client wants Transport Protocol as HttP and message format XML for his simplicity whereas .NET Client want transport protocol to be TCP and message formate to be Binary for the performance point of view so in this scenario we Create a Single WCF service with two endpoints one for each client.


Below figure shows Single WCF Service with two End Points.


When to use WCF Over WEB API :- If you do'nt have any restriction about the .NET framework version that is limitation for .NET 3.5 then you have to create Restful Services in Web API rather than WCF because WCF required more configuration settings for Restful Services . If you have existing SOAP service and you want to create more clients for RESTful services then you have to use WCF services.
WCF does not provides any MVC type support whereas Web API supports MVC type architecture support.
WCF is best suitable choice if you are using .NET 3.5.
WCF supports multiple transport protocols like TCP,UDP and Named Pipes.Whereas WEB API supports only HTTP Protocols only.
WEB API supports convention based CRUD operations with the help of HTTP Verbs like GET,PUT,POST and Delete.
WEB API provides support for Content Negotiation like provides choice for JSON/XML/Other Formates for response.
WEB API is Tightly coupled with HTTP.
WCF is better options when you want Serialization for the data over the network.
WCF has rich data contract and it is easy to self hosting.
WEB API is completely Open Source so it is better choice for creating Restful Services over the .NET Framework.


No comments:

Post a Comment

Creating First WEB API Project from scratch ?

  For creating Web API project open your Visual Studio Editor and Create New Project as shown in below figure. Now you have to select  ASP.N...