In this ASP.NET Interview Questions Series, so far we have covered questions related to the core of ASP.NET technology. In this part-6 of ASP.NET Web API Tutorial series, we will cover top 10 ASP.NET Web API interview questions related to ASP.NET Web API framework. What we have covered so far can be summarized as follows:
- Part 1 – Interview Questions on State Management and ASP.NET Controls.
- Part 2 – ASP.NET Interview Questions on Globalization and Localization, Culture etc.
- Part 3 – Interview Questions on Cache Management & Security in ASP.NET.
- Part 4 – ASP.NET Interview Questions on Security in Detail.
- Part 5 – Top 10 ASP.NET AJAX Interview Questions
You can follow here to create your first Single Page Application using AngualarJS and Web API, covering all CRUD (Create/Retrieve/Update/Delete) Operations. Also, you can find the list of more Advanced AngularJS Interview Questions here.
- A. GET
- B. POST
- C. DELETE
- D. PUT
For a complete online test and Practice Exams on Web Technologies, Click Here.
Correct Answer: D
For a comprehensive list of ASP.NET MVC Interview Questions, follow here.
ASP.NET Web API Interview Questions List
- What is ASP.NET Web API?
- What are the advantages of using ASP.NET Web API?
- What new features are introduced in ASP.NET Web API 2.0?
- WCF Vs ASP.NET Web API?
- WCF REST Vs ASP.NET Web API?
- Is it true that ASP.NET Web API has replaced WCF?
- MVC Vs ASP.NET Web API?
- How to return View from ASP.NET Web API method?
- How to restrict access to Web API method to specific HTTP Verb?
- Can we use Web API with ASP.NET Web Form?
More Web API Interview Questions
ASP.NET Web API is a framework that simplifies building HTTP services for broader range of clients (including browsers as well as mobile devices) on top of .NET Framework. Using ASP.NET Web API we can create non-SOAP based services like plain XML or JSON strings etc. with many other advantages including:
- Create resource-oriented services using the full features of HTTP.
- Exposing services to a variety of clients easily like browsers or mobile devices etc.
Using ASP.NET Web API has a number of advantages, but core of the advantages are:
- It works the HTTP way using standard HTTP verbs like GET, POST, PUT, DELETE etc for all CRUD operations.
- Complete support for routing.
- Response generated in JSON or XML format using MediaTypeFormatter.
- It has the ability to be hosted in IIS as well as self-host outside of IIS.
- Supports Model binding and Validation.
- Support for OData.
- and more….
More new features introduced in ASP.NET Web API framework v2.0 are as follows:
- Attribute Routing
- External Authentication
- CORS (Cross-Origin Resource Sharing)
- OWIN (Open Web Interface for .NET) Self Hosting
- Web API OData
You can follow a good Web API new feature details on Top 5 New Features in ASP.NET Web API 2 here.
Actually, Windows Communication Foundation is designed to exchange standard SOAP-based messages using variety of transport protocols like HTTP, TCP, NamedPipes or MSMQ etc. On the other hand, ASP.NET API is a framework for building non-SOAP based services over HTTP only. Back to top
Although both WCF REST and ASP.NET Web API follows the REST architecture but these have follow differences:
- Microsoft introduced “WebHttpBinding” to be used for creating WCF RESTful Services.
- HTTP Methods are mapped to attributes, for example, “WebGet” for GET method and “WebInvoke” for POST.
ASP.NET Web API
- As compared with WCF REST, Web API supports full features of HTTP.
- Its possible to host Web API in IIS as well as in an application.
- If we intended to use transport other than HTTP e.g. TCP, UDP or Named Pipes.
- Messag Queuing scenario using MSMQ.
- One-way communication or Duplex communication
public ActionResult GetEmployeeById()
//Code logic here.
What’s true about the above code.
- A. “GetEmployeeById” action method with be identified and called by name “GetEmployeeById”.
- B. “GetEmployeeById” action method with be identified and called by name “GetById”.
- C. Above code will generate an error because of wrong return type.
- D. Action method can’t be called because of duplicate action method names.
For a complete online test and Practice Exams on Web Technologies, Click Here.
Correct Answer: B
(A tricky Interview Question) No, we can’t return view from ASP.NET Web API Method. As we discussed in earlier interview question about difference between ASP.NET MVC and Web API that ASP.NET Web API creates HTTP services that renders raw data. Although, it’s quite possible in ASP.NET MVC application.
Back to top
Yes, ASP.NET Web API is bundled with ASP.NET MVC framework but still it can be used with ASP.NET Web Form. It can be done in three simple steps as follows:
- Create a Web API Controller.
- Add a routing table to Application_Start method of Global.asax.
- Make a jQuery AJAX Call to Web API method and get data.
We can provide an alias name for ASP.NET Web API action same as in case of ASP.NET MVC by using “ActionName” attribute as follows:
Exception Filter is basically a class that implements IExceptionFilter interface. While working with ASP.NET Web API, there can be scenarios where the code can generate unhandled exceptions. And for those unhandled exceptions, client will be receiving same generic error i.e. “Internal Server Error”. In order to tackle such unhandled exceptions, Exception Filters can be used.
You can follow here for a detailed article on Exception Handling in ASP.NET Web API with following implementation:
- What are Exception Filters in Web API?
- How we can create a Custom Exception Filter?
- How we can register Custom Exception Filter at different levels?
We can register exception filters for ASP.NET Web API in following different levels:
- Register Exception Filter from action
[MyCustomExceptionFilter] public Student Get(string id)
- Register Exception Filter from Controller
[MyCustomExceptionFilter] public class StudentsController : ApiController
//Controller detailed code.
- Register Exception Filter globally
CRUDWebAPI.MyCustomExceptionFilter ctrlr = new CRUDWebAPI.MyCustomExceptionFilter(); GlobalConfiguration.Configuration.Filters(ctrlr);
In this ASP.NET Web API Tutorial, we covered most important Interview Questions on ASP.NET Web API framework. Hopefully, it will be helpful for Web API developer Interview but along with these questions, do the practical implementation as much as you can. In Practical guide to ASP.NET Web API, you can find a good step by step approach for understanding and implementing ASP.NET Web API services.
Other Related Articles:
- MVC 3 Vs MVC 4 Vs MVC 5
- ASP.NET MVC Web API Service step by step
- Solution to browser back button event
- WebForms Vs ASP.NET MVC
- What’s new in WCF 4.5
- WCF Tutorial by Example
- Creating your first WCF REST Service
- Practical Guide to ASP.NET Web API
|Seattle, WA 98103||07-January-2017|
C# Software Developer (Web Services & API)
Sr. Web Developer (.Net/SharePoint)
.NET Web Application Developer
.NET Web Developer
|Austin, TX 78701||10-January-2017|
Sr. Web Developer & Designer
|Austin, TX 73301||20-January-2017|
|Westlake Village, CA||20-January-2017|
|Saint Paul, MN 55101||09-January-2017|
Windows C# .NET MVC Web Portal Developer in Ft. Lauderdale,FL
|Fort Lauderdale, FL||18-January-2017|
Entry Level Developer
|New Milford, CT 06776||13-December-2016|
.NET Web Developer (Denver, CO) (Long-term Contract)
ASP.NET / C# Software Developer (Web Services & API)
|Westlake Village, CA||13-January-2017|
Wellness Programs Web Developer (Consultant)
|Brooklyn, NY 11201||13-January-2017|
C# ASP.Net Web Developer
Front End Web Developer
C# .NET Web Developer - Green Bay, WI or Indianapolis, IN
|Indianapolis, IN 46218||28-December-2016|
Jr .Net Developer
Top 10 Web Developer Interview Questions and Answers:
- Top 10 HTML5 Interview Questions
- Top 10 ASP.NET Interview Questions
- Comprehensive Series of ASP.NET Interview Questions
- Top 10 ASP.NET MVC Interview Questions
- Top 10 ASP.NET Web API Interview Questions
- Top 10 ASP.NET AJAX Interview Questions
- Top 10 WCF Interview Questions
- Comprehensive Series of WCF Interview Questions
- Advanced AngularJs Interview Questions and Answers