.NET Provides different types of communication technologies like Web Services, WCF and Web API as below:
Web ServiceA web service is any piece of software that makes itself available over the internet and uses a standardized XML messaging system. XML is used to encode all communications to a web service.
- Based on SOAP and return data in XML form
- It Supports only HTTP protocol
- Consumed by any client that understands XML SOAP services
- Hosted only in IIS
- It is not a Open source
WCF
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, one can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a service hosted by IIS, or be a service hosted with in an application.
- Based on SOAP and return XML data, which is heavy compare than JSON
- Supports multiple protocols like TCP, HTTP, HTTPS, Names Pipes, MSMQ via configuration
- Consumed by any client which is able to understand XML SOAP services
- Can be hosted either by Self-hosting, IIS and using Windows Services
- Only support GET and POST verbs by [webget] and [webInvoke]
- Supports XML, JSON and ATOM (an XML based format which defines XML elements and their meaning) data formats
- Can be configured to support REST over HTTP by enabling "webhttpbindings"
- More reliable, when both client and server have .NET
- It's Implementation and configuration is complex, and overhead over Network
Web API
Web API is a framework to build HTTP services that reach a broad range of clients, including browsers and mobile devices, and is an ideal platform for building RESTful applications on the .NET Framework.
- Designed specifically for building HTTP Restful services on .NET Framework
- Support all features of HTTP like URIs, Request/Response, Headers, Caching and Versioning
- Supports GET, POST, PUT and DELETE HTTP verbs
- Can be self-hosted, hosted with in the application and on IIS
- It supports all MVC features like, controllers, action results, routing, filter, model binders, IOC container or dependency injection that makes it more simple and robust
- OWIN(Open Web Interface for .NET) is used for self-hosting
- Supports OData query options for sort, filter and page the of OData query
- Response can be formatted by Web API's MediaTypeFormatter into JSON, XML or any format which you can add as a MedialTypeFormatted
- It is stateless and easily readable as easy as JSON
What to choose between Web API or WCF?
Here are some of the differences between WCF and Web API:
- Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.
- 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.
- 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).
- Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets.