I found myself confused between WCF services and the new ASP.NET Web API, I researched about the differences and resulted to the following:
The following table describes the major features of each technology.
|WCF||ASP.NET Web API|
|Enables building services that support multiple transport protocols (HTTP, TCP, UDP, and custom transports) and allows switching between them.||HTTP only. First-class programming model for HTTP. More suitable for access from various browsers, mobile devices etc enabling wide reach.|
|Enables building services that support multiple encodings (Text, MTOM, and Binary) of the same message type and allows switching between them.||Enables building Web APIs that support wide variety of media types including XML, JSON etc.|
|Supports building services with WS-* standards like Reliable Messaging, Transactions, Message Security.||Uses basic protocol and formats such as HTTP, WebSockets, SSL, JQuery, JSON, and XML. There is no support for higher level protocols such as Reliable Messaging or Transactions.|
|Supports Request-Reply, One Way, and Duplex message exchange patterns.||HTTP is request/response but additional patterns can be supported through SignalRand WebSockets integration.|
|WCF SOAP services can be described in WSDL allowing automated tools to generate client proxies even for services with complex schemas.||There is a variety of ways to describe a Web API ranging from auto-generated HTML help page describing snippets to structured metadata for OData integrated APIs.|
|Ships with the .NET framework.||Ships with .NET framework but is open-source and is also available out-of-band as independent download.|
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. 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.
- Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
- Choose 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.
- Choose 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).
- Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.
- Choose Web API when you don’t have a requirement to support SOAP.