Difference between WCF and Web API

Difference between WCF and Web API

WCF vs ASP.NET Web 

This article will explain the difference between WCF and Web API and when to choose what. 

WCF(windows communication Foundation) is generally used for SOA (Service Oriented Architecture) which is used to build secure, reliable and transaction oriented Service whereas Web API is a framework which make easy to build HTTP services to reach broad client such as mobile, tablet and browsers. Basically Web API is light-weight architecture and ideal platform to build Restful applications.

 

WCF

Web API

SOAP based and supports different protocol like HTTP, HTTPs, TCP, NamedPipes

HTTP only. First-class programming model for HTTP. More suitable for access from various browsers, mobile devices etc enabling wide reach.

Support XML, JSON and ATOM and binary data format

Enables building Web APIs that support wide variety of media types including XML, JSON etc. Or whatever format you want to add as a MediaTypeFormatter

Supports Request-Reply, One Way, and Duplex message exchange patterns.

HTTP is request/response but additional patterns can be supported through SignalR and WebSockets integration.

Extensive configuration

It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.

Ships with .NET framework, It is not open source but can be consumed by any client that understands xml.

Ships with .NET framework but is open-source and is also available out-of-band as independent download.

Can be hosted with in the application or on IIS or using window service.

Can be hosted with in the application or on IIS.

 

When to choose what?

·       Use WCF to create reliable, secure web services that accessible over a variety of transports.

·        Use ASP.NET Web API to create HTTP-based services that are accessible from a wide variety of clients like mobile, tablet or browser.

·        Use ASP.NET Web API if you are creating and designing new REST-style services. 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. If you have an existing WCF service and you want to expose additional REST endpoints, use WCF and the WebHttpBinding.

·        Use WCF when you want to create a service 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 transport channels are unavailable.

·        Use Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).

comments powered by Disqus

Related Articles