Interest topics of WCF And Web API. Which One To Choose ?

Aykut Aktaş
4 min readOct 30, 2022

--

I think, this topic can be some of the very interesting questions asked in the interview process.

After reading to this 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?
WCF or Web API

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, Includes new updates to that technology.

Because WCF also suffered this fate, many people think that this Microsoft technology is obsolete.

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 fully functional in the .NET environment. As the Web API has no dependency on OS, it is conveniently implemented in the .NET CORE environment.

Note : The CoreWCF Project team has released the 1.0 version of CoreWCF, a port of WCF to the .NET Core platform. It provides a compatible implementation of SOAP, NetTCP, and WSDL. Usage in code is similar to WCF, but updated to use ASP.NET Core as the service host, and to work with .NET Core. This is the first major release of the project, and provides WCF functionality for .NET Core, .NET Framework, and .NET 5+. (Ref. Link : https://devblogs.microsoft.com/dotnet/corewcf-v1-released/)

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

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.

--

--

No responses yet