Difference between WCF and Web API and WCF REST and Web Service

Difference between WCF and Web API and WCF REST and Web Service

08 Aug 2024
Intermediate
567K Views
5 min read

Difference between WCF and Web API and WCF REST and Web Service: An Overview

The .Net framework has several technologies that allow you to create HTTP services such as Web Service, WCF, and now Web API. There are a lot of articles on the internet that may describe whom you should use, and gaining clarity on this topic is emphasized in ASP.NET Core training. Nowadays, you have a lot of choices for building HTTP services on the .NET framework.

In this Web API Tutorial, I would like to share my opinion with you on Web Service, WCF, and now Web API. For more information about Web API refer What is Web API and why to use it ?.

Web Service

It is based on SOAP and returns data in XML form. It supports only HTTP protocol. It is not open source but can be consumed by any client that understands XML. It can be hosted only on IIS.

WCF

It is also based on SOAP and returns data in XML form. It is the evolution of the web service(ASMX) and supports various protocols like TCP, HTTP, HTTPS, Named Pipes, and MSMQ. The main issue with WCF is its tedious and extensive configuration. It is not open source but can be consumed by any client that understands XML. It can be hosted within the application on IIS or using Windows service.

WCF Rest

To use WCF as WCF Rest service you have to enable webHttpBindings. It supports HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively. To enable other HTTP verbs you have to do some configuration in IIS to accept requests of that particular verb on .svc files. Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified. It supports XML, JSON, and ATOM data formats.

Web API

This is the new framework for building HTTP services easily and simply. Web API is open source an ideal platform for building RESTful services over the .NET Framework. Unlike the WCF Rest service, it uses the full features of HTTP (like URIs, request/response headers, caching, versioning, and various content formats). It also supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, and unit testing makes it more simple and robust. It can be hosted within the application or on IIS. It is lightweight architecture and good for devices that have limited bandwidth like smartphones. Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML, or whatever format you want to add as a MediaTypeFormatter.

Read More: Top Rest API Interview Questions and Answers 

Difference between WCF and Web API and WCF REST and Web Service

FeatureWCFWeb APIWCF RESTWeb Services (ASMX)
PurposeGeneral-purpose service frameworkBuilding HTTP services (RESTful)RESTful services over WCFBuilding SOAP-based services
CommunicationSOAP, REST, one-way, duplexRESTful (HTTP)RESTful (HTTP)SOAP (HTTP)
HostingIIS, self-hosting, WASIIS, self-hostingIIS, self-hosting, WASIIS
Programming modelContract-based, attributesMVC-basedContract-based, attributesContract-based
Data formatXML, JSON, binaryJSON, XML, and other formatsJSON, XMLXML
SecurityWS-Security, message securityHTTP-based securityHTTP-based securityWS-Security
ExtensibilityCustom bindings, behaviorsMiddleware, filtersCustom bindings, behaviorsLimited
Ideal forEnterprise-level services, interoperabilityModern web, mobile, and cloud appsRESTful services within WCFLegacy systems, interoperability
Summary

Web Services (SOAP), WCF (flexible but complex), WCF REST (limited REST support), and Web API (modern, RESTful, open-source) are all alternatives for implementing HTTP services in the .NET framework. Web API is appropriate for modern programs, WCF/REST for certain circumstances, and Web Services for legacy systems. Each choice has advantages and disadvantages, so choose cautiously based on your requirements.

FAQs

 WCF is used for SOAP-based service development, whereas Web API is utilized for both SOAP-based and RESTful service development. WCF does not provide support for MVC functionalities, although Web API does. WCF supports HTTP, UDP, and custom transport protocols, whereas Web API only supports HTTP.

Web and REST APIs are used to create apps that offer resources and communicate via HTTP. While REST outlines architectural limitations over a uniform interface, web APIs are a broad concept that, depending on implementation, can be RESTful.

Web services can only be hosted in IIS, but WCF can be hosted in IIS, Windows activation services, self-hosting, & Windows services. WCF is ideal for developing real-time applications because it is more dependable, quick, and robust than web services.

APIs allow applications to communicate with one another, whereas web services allow machines to communicate with one another. Web Services require a network connection to function, whereas APIs may or may not require a network connection to function. Web services necessitate the use of SOAP and XML, which are no longer the most widely used standards.

WCF is a Microsoft technology for developing web services (mainly using SOAP, but it is sufficiently customizable that it may also be used for REST.
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 9th time in a row (2016-2024). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Accept cookies & close this