Sunday, February 19, 2017

WCF over Web API

Few folks asking me – When to use Web API over WCF. Many technical blogs have given uses of both WCF and Web API and their primary differences. It’s not so difficult to decide on right technology for service until unless we have clear picture/vision on the consuming clients/applications and their dependency factors.  I will try to post my comments on when to use which technology. Post me your suggestions/comments on the same.

When we decided to have a service layer in our application(s) for sure there would be depending factors on the service(s).

If the application designed under service oriented architecture, then we may go for WCF as it is a development platform for SOA. We can keep WCF features aside for a while, it provides multiple transport protocols. It’s time to think what sort of protocols client would use to consume the service. If INTRA-net application consumes the service, then we can deliver TCP end-point. If another client wants to have it thru HTTP, we can also deliver HTTP end-point, etc.

If services need to consumed by broad range of clients including desktop/laptop browsers, mobiles, iPhone and tablets, IoT, WPF client, Windows 8 Phone, Windows Surface devices etc. then we can use light weight RESTful service which is a Web API.
Unlike WCF Restful service, it uses full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats) and you don't need to define any extra config settings for different devices unlike WCF Rest service.

ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
We can leverage WCF to build secure, reliable, and transactional services that can support messaging, duplex communication and fast transport channels like, TCP, Named Pipes or UDP.

In other note, we shouldn’t compare Web API with MVC, those are totally unrelated thing. MVC is an architecture or design pattern to build application, on the other hand API's are built as a component of application.

We will find features/advantages/differences from google anyway, so I am not talking on this here.

No comments: