locked
Difference between ASP.NET Web API and WCF RRS feed

  • Question

  • User-545631939 posted

    Gurus!

    I need your help in knowing the difference between ASP.NET Web API and WCF. From what I have been reading, it seems the Web API is a more lightweight version of WCF. Is that true Gurus? If I understand correctly, it is also used to directly connect from the web server to the database, without any middle tier in between. Please correct me if I am wrong Gurus.

    Is it possible to develop a full fledged SOA solution by utilizing the ASP.NET Web API? What are the limitations of this framework Gurus? And what are the typical scenarios in which it is advisable to go with the Web API rather than WCF? Enlighten me, O Gurus!

    Novice Kid

    Monday, September 8, 2014 1:56 PM

Answers

  • User1779161005 posted

    In short, you can build services with either. Web API is HTTP focused, whereas WCF is SOAP focused. Web API, given its HTTP focus, allow for better/easier reach to different platforms (JavaScript, iOS, Android, etc), whereas WCF, given its SOAP nature has some features that you might not get from the simpler Web API style (but to be honest, people rarely use those features), but at the expense of needing a heavier and more complicated framework.

    The industry in general (meaning software beyond the Microsoft ecosystem) is leaning more towards Web API and SOAP is being used less and less.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 8, 2014 2:04 PM
  • User-760709272 posted

    Web API is just a way of writing REST web services that you host in IIS, whereas WCF is a whole communications framework.  It can do REST if you want, but it can also do non-REST, SOAP style webservices allowing data to be sent and received in a better defined way, it allows clients to discover the methods and objects available etc, it also have support for various web protocols and also some non-standard ones, that allow for better control over security, protocols that support "sessioning" where server-side state is maintained for the life of the client.  WCF also doesn't have to be hosted in IIS, it can be hosted in IIS or in any process such as a desktop app, a windows service etc.  WCF also supports a far wider range of transport mechanisms, not just http.  It supports binary transfer via TCP, it supports communication over MSMQ and so on.  Web API can do a very very very small subset of what WCF can do, but if Web API does everything you need there is no reason not to use it.  WCF can be quite complicated to setup and configure.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 8, 2014 2:06 PM

All replies

  • User1779161005 posted

    In short, you can build services with either. Web API is HTTP focused, whereas WCF is SOAP focused. Web API, given its HTTP focus, allow for better/easier reach to different platforms (JavaScript, iOS, Android, etc), whereas WCF, given its SOAP nature has some features that you might not get from the simpler Web API style (but to be honest, people rarely use those features), but at the expense of needing a heavier and more complicated framework.

    The industry in general (meaning software beyond the Microsoft ecosystem) is leaning more towards Web API and SOAP is being used less and less.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 8, 2014 2:04 PM
  • User-760709272 posted

    Web API is just a way of writing REST web services that you host in IIS, whereas WCF is a whole communications framework.  It can do REST if you want, but it can also do non-REST, SOAP style webservices allowing data to be sent and received in a better defined way, it allows clients to discover the methods and objects available etc, it also have support for various web protocols and also some non-standard ones, that allow for better control over security, protocols that support "sessioning" where server-side state is maintained for the life of the client.  WCF also doesn't have to be hosted in IIS, it can be hosted in IIS or in any process such as a desktop app, a windows service etc.  WCF also supports a far wider range of transport mechanisms, not just http.  It supports binary transfer via TCP, it supports communication over MSMQ and so on.  Web API can do a very very very small subset of what WCF can do, but if Web API does everything you need there is no reason not to use it.  WCF can be quite complicated to setup and configure.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 8, 2014 2:06 PM
  • User1779161005 posted

    Just as a side note: Web API is OWIN hostable, so it too can be hosted outside of IIS.

    Monday, September 8, 2014 2:09 PM
  • User-545631939 posted

    Thanks a lot Gurus AidyF and BrockAllen!

    I just had one more question - is the Web API used for direct communication between the web and database tiers? Does it do away with the middle tier that is typically hosted on an application server? Or can we use the Web API too to create something like a WCF facade?

    Seeking enlightenment Gurus!

    Novice Kid

    Monday, September 8, 2014 2:17 PM
  • User1779161005 posted

    Yes, Web API can be used to abstract DB access. Web APIs (given their HTTP nature) are about modeling access to resources.

    Monday, September 8, 2014 2:22 PM
  • User-545631939 posted

    Thanks again Guru BrockAllen!

    But if the Web API does away with the middle tier, where would you put your business logic? On the web server itself? Doesn't that cause a paradigm shift in the architecture? And wouldn't putting the business logic on the web server come with its own security concerns?

    Novice Kid

    Monday, September 8, 2014 2:29 PM
  • User1779161005 posted

    I think of a Web API layer as a middle tier, so that's no different. And as always, logic could be either or both.

    Monday, September 8, 2014 2:35 PM
  • User-545631939 posted

    But can Web API be used the same way as WCF, to create a facade for the business logic on the application server, which is then accessed by the web pages through the proxy classes? Please let me know Guru BrockAllen, many thanks once again!

    Novice Kid

    Monday, September 8, 2014 2:43 PM
  • User1779161005 posted

    Yes.

    Monday, September 8, 2014 2:45 PM
  • User-760709272 posted

    Thanks again Guru BrockAllen!

    But if the Web API does away with the middle tier, where would you put your business logic? On the web server itself? Doesn't that cause a paradigm shift in the architecture? And wouldn't putting the business logic on the web server come with its own security concerns?

    Novice Kid

    Web API\WCF doesn't really "replace" a standard layer like a business layer, it just provides functionality via a service\web interface.  It's up to you do define what role that service has.  For example you might having a banking service that takes a card number, and amount, and debits the card that amount.  The calling code then just passes the info and the task is done.  In that instance the web service would have a lot of business logic, such as working out what security features the card uses, validating the information is correct, making decisions about when it isn't correct, making decisions about when 3DS is to be used and so on and so on....all that logic is hidden from the client.  Or you might have a web service that is simply a way to select from and update a data store like a database.  So the calling code will do things like "GetPerson" and "UpdatePerson", and that service will have no business logic, but the code that calls the service does all of the business logic.

    It's basically up to you do define where your logic sits and what roles your various layers are going to do.

    Monday, September 8, 2014 3:23 PM