WCF or ASP.NET Web APIs ? My thought

ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. The new ASP.NET Web API is a continuation of the previous WCF Web API projection. WCF was originally created to enable SOAP-based services and other related bindings. However, for simpler RESTful or RPCish services (think clients like jQuery) ASP.NET Web API is a good choice.

Let us see what do we need to understand as an architect to implement your service oriented architecture using WCF or ASP.NET web API. With code samples, we will elaborate on WCF Web API’s transition to ASP.NET Web API and respective constructs such as Service vs. Web API controller, Operation vs. Action, URI templates vs ASP.NET Routing, Message handlers, Formatters and Operation handlers vs Filters, model binders. WebApi offers support for modern HTTP programming model with full support for ASP.NET Routing, content negotiation and custom formatters, model binding and validation, filters, query composition, is easy to unit test and offers improved Inversion of Control (IoC) via DependencyResolver.

  • WCF enables building services that support multiple transport protocols (HTTP, TCP, UDP, and custom transports) and allows switching between them. whereas ASP.Net Web API is HTTP only. First-class programming model for HTTP. More suitable for access from various browsers, mobile devices etc enabling wide reach.

  • WCF enables building services that support multiple encodings (Text, MTOM, and Binary) of the same message type and allows switching between them, whereas ASP.Net Web API enables building Web APIs that support wide variety of media types including XML, JSON etc.

  • WCF Supports building services with WS-* standards like Reliable Messaging, Transactions, Message Security, on other hand ASP.Net Web API 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.

  • WCF supports Request-Reply, One Way, and Duplex message exchange patterns, and ASP.Net Web API through HTTP supports 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.

  • WCF Ships with the .NET framework, whereas ASP>net Web API also ships with .NET framework but is open-source and is also available out-of-band as independent download.

To summarize, we should 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.

Comments are closed