In my current company we are going to start with Web API’s so I just thought of doing some reading and figure out questions for below answers.

Difference between WCF and ASP.Net Web API?
Why not SOAP? – it is also XML based.
Is WCF dead? If not, when to use WCF or ASP.Net Web API?

Difference between WCF and ASP.Net Web API?
  • WCF was conceived back in its Indigo and .NET 3 days, the main goal was to support/exchange SOAP-based messages using variety of transport protocols like HTTP, TCP, NamedPipes or MSMQ etc.
  • ASP.NET API is a framework for building non-SOAP based services over HTTP only.

Points of interest

  • In .NET 3.5, WCF got a new binding, “WebHttpBinding” — a new binding that helped creating non-SOAP service over HTTP, better known as a RESTful service. (WCF Rest)
    • The WebHttpBinding was not enough, and after WCF 3.5 was released, a new set of tools was created – the WCF REST Starter Kit.
    • REST starter kit was an attempt to enrich the support of WCF 3.5 for HTTP services
      • Add better client-side support for .NET apps
      • Extend the server side support for other content types
      • Enable response and request caching
      • Inspection of messages and so forth.
    • Unfortunately, this great toolkit was never officially released
  • In .NET 4, Some of the server side features of REST Starter Kit was integrated in WCF 4 but we didn’t get any of the client-side libraries.
    • We did get most of the service-side features (excluding the new inspectors). Some were well-integrated into WCF while others required the use of ASP.NET (by turning on the ASP.NET compatibility mode).

So with WCF 4 we had some support for “Web” HTTP services, but it wasn’t that perfect – to get some of the features you needed IIS hosting and ASP.NET, not all types of requests were supported easily.

Why not SOAP? – it is also XML based.
  • SOAP allows us to place all the knowledge required by our service in the message itself, disregarding its transport protocol, whether it is TCP, HTTP, UDP, PGM, Named Pipes etc
  • HTTP is an application-level protocol, and as such it offers a wide variety of features:
    • It supports verbs that define the action, GET, POST/PUT, DELETE
    • Message headers that are very meaningful and descriptive – headers that suggest the content type of the message’s body, headers that explain how to cache information, how to secure it etc.
    • Message body that can be used for any type of content, not just XML content as SOAP enforces (and if you want something else – encode it to base64 strings and place it in the SOAP’s XML content).
      • The body of HTTP messages can be anything you want – HTML, plain XML, JSON, binary files (images, videos, documents…)

Points of interest

  • The use of HTTP has evolved over the years. Application-level protocol architectural styles such as Hypermedia APIs or this link have emerged on top of HTTP.
    • These, in turn, harness the power of HTTP to create resource-oriented services, and better define the stateless interaction between clients and services

SOAP is still useful for building messages when you don’t have an alternative application-level protocol at your disposal, or when you want to use SOAP across the board while considering HTTP as no more than another way to pass messages (for example, use HTTP because it can cross firewalls more easily than TCP).

Is WCF dead? If not, when to use WCF or ASP.Net Web API?
  • ASP.NET Web API framework is not going to replace WCF. It’s just another way of building services that are non-SOAP based e.g. plain XML, JSON string etc. – This mean WCF certification still holds value J
  • WCF is still the best choice for
    • Messag Queuing scenario using MSMQ.
    • One-way communication or Duplex communication
    • If we intended to use transport other than HTTP e.g. TCP, UDP or Named Pipes.

Above information is best as per knowledge and readings. My understanding might be wrong at few places.


One thought on “WCF vs ASP.NET Web APIs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s