Today there are many different types of applications which a user access for different purposes.There are apps for mobile phones and tablets,web applications which are accessed through different devices,embedded applications and many others.
All of these applications need to communicate with the outer world to achieve different functionalities.For example a weather app might need real time weather information.
Limitations of Web Services
Web services were used to provide different applications the required data.SOAP based services are useful for application to application communication.But SOAP based services are not easy to consume by different types of clients.To build services today means that services should support different types of clients such as different mobile platforms such as iOS,android,windows as well as desktop clients.
HTTP protocol is natively supported across different platforms..So this means that HTTP services can be consumed by the different platforms and by variety of clients.But web services are SOAP based and so doesn’t support all the features of HTTP.
If our services are to be used across different platforms then they should support all the HTTP features.
Configuration is not very easy
If we develop a web service using ASP.NET then a proxy needs to be generated on the client to consume the web service. So these limitations doesn’t make the web services suitable for different types of clients.
Web API represents an interface which is used by the web clients to send and receive information.The interface is exposed as HTTP services which can be invoked by clients.In other words we can say that WebAPI represents a HTTP service which is accessible by different types of clients.
HTTP is used as just a transport protocol
Web Services use HTTP as just a transport protocol.HTTP protocol is an application protocol and provides different features such as:
- Support for different verbs such as GET,PUT.
- Headers which provide important information about the request.
- Can use different content types not just XML.
Some of the differences between WCF and ASP.NET WebAPI are:
- ASP.NET Web API is used to build HTTP services on the .NET framework.WCF is used for creating services which supports different protocols such as HTTP,TCP.
- It is part of ASP.NET platform.
- Unlike WCF services it supports only HTTP protocol.
- As HTTP services can be accessed by different platforms so WebAPI is supported across different platforms.Unlike web services WebAPI services can be easily consumed by different types of clients as the configuration is simple.
- ASP.NET WebAPI was intrduced to create HTTP services.It doesn’t use the SOAP protocol.
- It shares many features with MVC such as routing ,model binding.
- Supports convention based action methods.In WCF services requests are mapped to .svc files whereas in WebAPI requests are mapped to action methods.
- More suitable for building RESTful applications as compared to WCF.
- SOAP is more inclined towards XML but today json is the most common format understood by different clients.WebAPI supports different content types including JSON.
- It is relatively easier to build REST services in WebAPI as compared to WCF
REST stands for Representational State Transfer and is an architectural pattern which is based on HTTP and used to create services using the HTTP protocol.
So when considering using WebAPI vs WCF for creating services it would be helpful to consider some of the above points.