difference-between-WCF-WebAPI-technothirsty

Difference Between WCF and WebAPI

difference-between-WCF-WebAPI-technothirsty

Hello folks, hope you all are doing well. Today I want to explain regarding difference between WCF and Web API and which should you pick for your project with detailed explanation. I have already discussed regarding Difference between WCF and Web Service and Difference between SOAP and REST, You should look into these concepts as well ,to understand difference between WCF and Web API.

Let’s try to understand WCF and Web API in brief.

WCF

  1. It is based on SOAP and return data in XML form.
  2. It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ.
  3. The major issue with WCF is tedious and extensive configurations.
  4. Supports any client who supports XML.
  5. Can be hosted as self hosted, IIS and as a Windows Service also.

Web API

  1. This is used to build HTTP service with easy and simple way.
  2. Used to build REST-ful services over the .net Framework
  3. It uses full features of HTTP(like URIs, Request Response headers, caching, versioning, various content formats)
  4. Also supoorts MVS features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.
  5. Hosted with in application or on IIS.
  6. It is light weight and good for devices which have limited bandwidth like smart phones.

 

Lets find difference between WCF and Web API as below by comparing features.

Features Web API WCF
Endpoint HTTP based Soap based
Service Type Front End Back End
Supports caching, compression, versioning None of as Web API
Uses Framework Of asp.net WCF
Orientation Resource Oriented Service Oriented
Transports http only http, tcp, MSMQ, Named pip
Message Pattern Request Reply Request reply, One way, duplex
Configuration Overhead Less Much
Security Lesser than WCF (web standard security) Very high(WS-I standard)
Hosting IIS, Self Hosting IIS, Windows Service, Self hosting
Performance Fast Slower than Web API
Introduced in .Net 4.0 .Net 3.5
Content format Any media format SOAP+XML
Service Interface URL Patternd, HTTP methods Service Contracts
State Management Stateless Stateless with Per Call
Caching mechanism Built in to HTTP prefer application control Handled by application
Error handling HTTP status coder filters, exceptions Faults, behaviors
Types Opt-out Opt-in
Uses Use SignalR for asynchronous signalling(polling,websocket,long polling) Use WCF data services for full OData support

 

Now Let’s try to understand when should we pick either of them in your project.

  1. Within the company Network and .NET based clients : Use WCF with TCP binding (Fast communication than HTTP).
  2. Outside the company Network, and use diverse technologies like PHP, Python etc: Use Web API with REST
  3. WCF is a best fit for scenarios like message queues, duplex communication, end-to-end message security, one way messaging, distributed transactions, etc. WEB API is a best fit to create a resource-oriented services using HTTP/Restful and it works well with MVC-based applications.
  4. WCF was created to develop SOAP-based services and bindings. Since WCF is SOAP based, which uses standard XML schema over HTTP, it could lead to slower performance. WEB API is a better choice for simpler, light weight services. WEB API can use any text format including XML and is faster than WCF.
  5. WEB API can be used to create full-blown REST Services. WEB API doesn’t require any data contracts and doesn’t require configurations to the level of WCF.
  6. If performance and quick development cycles are your criteria, WEB API is a better choice over WCF.