What is WCF?

WCF stands for Windows Communication Foundation. It is used to create a distributed and interoperable Applications. WCF is an effective platform for developing service-oriented applications. It allows developers to create secure, reliable, and high profile development solutions which can be integrated across platforms and interoperate with existing investments.

In this tutorial, you will learn

What is Web API?

ASP.NET Web API is a framework which allows you to build HTTP services for browsers and mobile devices. It is an ideal platform for developing RESTful applications on the ASP .NET Framework.

The ASP.NET Web API is an extensible framework for building HTTP based services that can be accessed in different applications on different platforms such a web, windows, mobile devices, etc.

Why use WCF?

Stack Overflow Questions ASP.net web API vs. WCF

Here, are pros/benefits of using WCF:

  • WCF is an ideal option if you are planning to use .NET Framework 3.5.
  • WCF support multiple protocols such as HTTP, TCP, Named pipe.
  • WCF service is useful if you want to build service with standards like Transactions Messaging security and Reliable Message Security.
  • You can use Request-Reply, One Way, and Duplex message exchange patterns with WCF.

Why used Web API?

Google Trends WCF vs. ASP.Net web API

Here, are pros/benefits of using web API:

  • Web API provides supports for convention-based CRUD Actions since it works with HTTP verbs ( GET, PUT, POST, and DELETE)
  • It is easy to define, expose, and consume in a REST-ful way.
  • ASP.Net Web API allows you to showcase your data and services to various devices.
  • Web API is open source, so it is an ideal option for creating RESTful services over the .NET platform.
  • Allows you scalable, decoupled development of a Web Service which can be shared and used by other developers to access web services.
  • It is also helpful to build simple, non-SOAP-based HTTP Services.

Characteristics of WCF

  • Highly configurable transports
  • Better options for serialization
  • Well-integrated with IIS
  • Easy for self-hosting
  • Very rich metadata
  • Complex model for publication
  • Rich data contracts

Characteristics of Web API

  • Tightly coupled to HTTP
  • Easy to test
  • Offers support for content negotiation
  • Allows open-ended formatting
  • No reliance on a platform
  • Solid resource-orientation
  • Level 2 experience with nascent hypermedia support

WCF Vs Web Service

Parameter WCF Web API
Message Exchange Pattern Request reply, one-way, or duplex. By default request-reply only. However, additional message pattern can be supported with web sockets integration.
Hosting IIS hosting, Self-hosting & works activation services. Self-hosting & IIS hosting.
Open Source It is not open source software. It is shipped with.Net framework but is open source. It is also available as an independent download.
Support for MVC features WCF does not provide any support for MVC features like controllers, routing, filter, auction results, etc. ASP.NET Web API supports MVC features like routing, controllers, results, filter, action, etc.
Encoding support Text, MTOM, and Binary. Default support for UTF-8 encoding format.
Support for Support for HTTP, UDP, and custom transport protocol. Supports only HTTP protocol
Use of model User attributed based programming model. Maps HTTP verbs to methods
Configuration Uses web.config and attributes to configure a HttpConfiguration class but not on the web.config Service. Web API can be configured using web.config service.
RESTful services It offers supports for RESTFUL service but with limitations. Ideal for building RESTFUL services.

The deciding factor for WCF vs. Web API

Following is a quick checklist to help to determine whether to use WCF or Web API

Scenario WCF 4.5 ASP.NET Web API
Requires support for scenarios like Message queues, end to end message security, duplex communication, distributed transactions, etc. Select Do NOT Select

When you already have existing working WCF services and Wants to add HTTP support additionally. Select Do NOT Select

One code base to provide support both SOAP and RESTful endpoints. Select Do NOT Select

Wants to create a resource-oriented service over HTTP. Do NOT Select Select

Your project is an MVC application and wants some functionality over HTTP. Do NOT Select Select

You want to build only an HTTP / RESTful services Do NOT Select Select

Summary

  • WCF stands for Windows Communication Foundation.
  • ASP.NET Web API is a framework which allows you to build HTTP services for browsers and mobile devices.
  • The major advantage of using WCF platform is that it allows you to support multiple protocols such as HTTP, TCP, Named pipe.
  • The biggest benefit of using Web API is that it is easy to define, expose, and consume in a REST-ful way.
  • WCF offers better options for serialization
  • Web API offers support for content negotiation
  • WCF does not provide support for MVC features like controllers, routing, filter, auction results, etc. while Web API supports MVC features like routing, controllers, results, filter, action, etc.
  • You should select Web API if you want to provide support both SOAP and RESTful endpoints while you should select WCF if you want one code e base to provide support both SOAP and RESTful endpoints.

 

YOU MIGHT LIKE: