DEV Community

Tural Suleymani
Tural Suleymani

Posted on

Differences Between WCF And Web API. Which One To Choose?

In this article, we will discuss some of the very interesting questions asked in the interview process.

After finishing the article, you will be able to easily find answers to the following questions:

Is it worth learning WCF? Is WCF dead?
What are the differences between WCF and Web API?
When should I use WCF and when should I use Web API?
For many years, there have been various technologies for writing services on the .NET platform.

These technologies initially included .NET remoting, Web Services, Enterprise Services, and Socket communication.

With the development of .NET, the work done by these technologies was later integrated into WCF (Windows Communication Foundation).

But recently, due to the widespread adoption of REST services, the Web API has somewhat overtaken WCF services.

Currently, the most popular service writing technologies on the .NET platform are undoubtedly Web API and WCF.

Does it matter to learn WCF if we have web API?
YES! WCF is not obsolete as a technology! Only when Microsoft company reaches the peak of development in its technologies,

it rarely includes new updates to that technology. Because WCF also suffered this fate, many people think that this Microsoft technology is obsolete.

WCF is not dead

What are the differences between WCF and Web API?
You will most likely come across this question when you are in an interview.

1) WCF is currently only fully functional in the .NET environment. As the Web API has no dependency on OS, it is conveniently implemented in the .NET CORE environment.

PS: According to my research, there are no plans to integrate into .NET CORE yet. Although they add a WCF client and dotnet-svcutil tool in the .NET environment, it does not replace WCF in WinOS in any case. (here the word Windows) is due to.

2) WCF can work with several protocols (TCP, HTTP, custom ..), and also allows you to easily switch from one protocol to another. But ASP.NET Web API can only work with HTTP protocol.

3) Based on point 2, we can say that WCF is more abstract in terms of protocol because it has a protocol-independent architecture. The WEB API is implemented in a protocol-dependent manner.

4) WCF works with the SOAP protocol and describes the internal structure of the service by generating WSDL. Due to this, client proxy classes are generated. But in WEB API they usually do this with automatically generated helper HTML pages.

5) WCF supports the principle of unidirectional, duplex messaging, while WEB API only supports the principle of request-response. For additional messaging templates, the image should use SignalR or Web sockets.

6) WCF supports higher-level protocols (Transactions, Realizable Messaging) based on the WS-* (w-es-star) standard. The Web API does not support any of these.

7) WCF services support various encoding formats (MTOM, binary, etc.), but in the Web API they are replaced by media formats (JSON, XML, etc.)

8) WCF is a service creation technology with greater capabilities than WEB API

WCF vs Web API
9) Although WCF works with SOAP, you can also write REST services using certain configurations.

10) Unlike WCF, the client aspect of WEB API is wider, it has the ability to COMFORTABLE work with more client devices.

11) Web API uses URL patterns and HTTP methods as a service interface. But WCF uses service contracts as a service interface.

12) The cache mechanism of the WEB API is handled by the HTTP protocol, while in WCF the cache is handled by the written service.

13) WEB API does not require any config and no data contract, unlike WCF. WCF requires a data contract for the complex types it accepts and returns.

14) Web API is faster than WCF.

15) If performance and fast development process are interesting to us, then WEB API is the best choice

When should I use WCF and when should I use Web API?
If you need to write a protocol-independent service, then WCF is the best option. Thus, 2 clients of service can work with WCF, receiving data in different forms with different protocols. This feature is not available in the WEB API.
WCF is the best choice if you need to write a service for enterprise systems.
Web API is the best option for writing mobile devices and device-oriented services.
WEB API is easier to learn, requiring less configuration than WCF.
If there is a service written in WCF at your workplace (which is very likely) you need to know WCF to accompany it.

Want to dive deeper?

Regularly, I share my senior-level expertise on my DecodeBytes YouTube channel, breaking down complex topics like .NET, Microservices, Apache Kafka, Javascript, Software Design, Node.js, and more into easy-to-understand explanations. Join us and level up your skills!

Top comments (0)