WCF vs. Web API - Good to know the differences

February 19, 2015

Nowerdays the requirement for a lot of web services is to be - more or less - RESTful.

If you have a look on the Microsoft stack, you find selveral ways to implement services which can receive HTTP requests and where you can build up a service.

Here we want to compare WCF (Windows Communication Foundation) and ASP .NET Web API

What is WCF?

WCF was first released with the .NET Framework 3.0 in 2006 and then recived several improvements with .NET 3.5 and .Net 4.0

In the past, SOAP was (and still is) used for a lot for service-oriented communication. With WCF, Microsoft wanted to combine several seperate implementations spread over the .NET library.

And WCF is really that - they put the possibilities of the following technologies into WCF

  • Interoperable Web Services
  • Binary .Net - .Net Communication
  • Distributed Transaytions
  • Support for WS-* Specifications
  • Queued Messaging
  • RESTFul Communication

What is ASP.NET Web API?

Web API was released in August 2012, together with the .NET Framework 4.5.

As you can see, it is much newer than WCF. The goal for Web API is different from WCF. Microsoft wanted to build a lean, yet powerful framwork, focused on RESTful services.

And with this, we come to the comparison.

  • Multiple transport protocols (HTTP, TCP, UDP, and custom transports)
  • Multiple encodings (Text, MTOM, Binary) 
  • Services with WS*-standards (reliable messaging, tranactions, security)
  • Multiple message exchange patterns (Request-Reply, One Way and Duplex)
  • WCF SOAP services can be described in WSDL. (Good for automatic client proxy generation)
  • Included in .NET Framwork
  • HTTP only
  • Wide variaty of media types - most important JSON and XML
  • Basic protocols and formats (HTTP, WebSockets, SSL, JSON, XML). No support for higher protocols (reliable messaging, transactions...) 
  • Mainly Request-Reply (HTTP) but also additional patterns though SignalR and WebSockets
  • No support for SOAP => no WSDL. REST Services can ve described by auto-generated HTML help pages
  • Included in .NET Framwork. Can also be independently downloaded. (Open-Source)