Asp Dot Net Web Api Interview Questions


Q#1. What is ASP.NET Web API?

Ans. ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.


Q#2. Why is Web API required? Is it possible to use RESTful services using WCF?

Ans. Yes, we can still develop RESTful services with WCF. However, there are two main reasons that prompt users to use Web API instead of RESTful services. Web API increases TDD (Test Data Driven) approach in the development of RESTful services. If we want to develop RESTful services in WCF, you surely need a lot of config settings, URI templates, contracts & endpoints for developing RESTful services using web API.


Q#3. What is the difference between ASP.NET Web API and WCF?

Ans. Web API is a Framework to build HTTP Services that can reach a board of clients, including browsers, mobile, IoT Devices, etc. and provided an ideal platform for building RESTful applications. It is limited to HTTP based services. ASP.NET framework ships out with the .NET framework and is Open Source. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocol like HTTP, TCP, MSMQ, etc. It supports multiple protocols like HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out with the .NET Framework. Both Web API and WCF can be self-hosted or can be hosted on the IIS Server.


Q#4. Why select Web API?

Ans. It is used to create simple, non-SOAP-based HTTP Services It is also an easy method for creation with Web API. With WCF REST Services It is based on HTTP and easy to define, expose and consume in a REST-ful way. It is lightweight architecture and ideal for devices that have limited bandwidth like smartphones.


Q#5. When to prefer ASP.NET Web API over WCF?

Ans. It totally depends upon the requirement. Choose ASP.NET Web API is you want only HTTP based services only as Web API is a lightweight architecture and is good for the devices which have limited bandwidth. We can also create the REST services with the WCF, but that requires lots of configuration. In case, if you want a service that should support multiple transport protocol like HTTP, UDP, TCP, etc. then WCF will be a better option.


Q#6. Is it right that ASP.NET Web API has replaced WCF?

Ans. It’s a not at all true that ASP.NET Web API has replaced WCF. In fact, it is another way of building non-SOAP based services, i.e., plain XML or JSON string.


Q#7. Which .NET Framework supports ASP.NET Web API?

Ans. First Version of ASP.NET Web API is introduced in .NET Framework 4. After that, all the later versions of the .NET Framework supports the ASP.NET Web API.


Q#8. What are main return types supported in Web API?

Ans. A Web API controller action can return following values: Void – It will return empty content HttpResponseMessage – It will convert the response to an HTTP message. IHttpActionResult – internally calls ExecuteAsync to create an HttpResponseMessage Other types – You can write the serialized return value into the response body


Q#9. Can we consume ASP.NET Web API in applications created using other than .NET?

Ans. Yes, we can consume ASP.NET Web API in the applications created using another language than .NET but that application must have access/supports to the HTTP protocol.


Q#10. Web API supports which protocol?

Ans. Web App supports HTTP protocol.