Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net Web API vs WCF, which one should I choose in my project

I have read many articles in the web so far, about the differences between WCF and ASP.Net web API. Unfortunately I could not come up to a clear idea about what will serve my purpose. Most of the Articles I have read highlighted on the design point of view of the two web services. But I am confused what will work best for my project and why? Here is my brief description of the project.

I need to create a communication channel between two servers (both are written in C#). The servers will communicate using messages (certain type of commands). The messages sometimes can be only acknowledgements, and sometimes the messages may contain instructions to do some computation. For example, one message can be draw something, or send an SMS etc. And not necessarily the messages will involve any database transactions. But the messages can sometimes send large text files as payload (around 1-5 MB maxm). What I believe WCF is very will surely do this, but can I do the same with ASP.net web API. Because so far all the example I have seen for ASP.Net web api: they are good for RESTful services that manipulate some kind of DB store (GET, PUT, DELETE). But in my case I will need to expose service points that will

do some kind of processing such as return the value of a computation, sending and acknowledging messages, etc.

Not just manipulating a DB-store.

So, what should be the best and simplest way to do so? It is needed to be mentioned that I did not find any straight forward example of achieving this using ASP.Net web API.

like image 642
P basak Avatar asked Dec 16 '16 08:12

P basak


1 Answers

The Question you have asked is an overly-broad or primarily opinion-based, and its hard to give an example for what you have asked.

Important Points:

  • Firstly, if you are going to create a service which would be used on different platforms, then go with WCF.
  • Secondly, if you are creating internet service which is going to use external resource, then go with Web API.
  • Web API is the best choice if you are going to create a service for low bandwidth devices or mobile devices to access client.HTTP request/response is also more readable as compared to SOAP because it contains header, body, etc. which makes it complex.

Just take few minutes and read the below article, until you get complete understanding of few principles.

Original Source Can be found Here, Here and Here.

To whom choose between WCF or WEB API :

  1. Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
  2. 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.
  3. 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).
  4. Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.

Why to choose Web API

  • Web API doesn't have tedious and extensive configuration like WCF REST service.
  • It is very simple, creating service with Web API. Where as With WCF REST, service creation is bit difficult (requires clear understanding of configurations).
  • Web API is only based on HTTP and HTTPS and easy to define, expose and consume in a REST-full way.
  • Web API is light weight architecture and good for devices which have limited bandwidth like smart phones.

My Opinion:

  • Simplest way to do so - Web API (Since you dont have any examples for this)
  • Hardest Way is (Configurations) - WCF (Better go with WCF, since you have examples)

I hope this gives you a clear idea about what to choose...

like image 155
RajeshKdev Avatar answered Sep 24 '22 04:09

RajeshKdev