Top 50 Asp Interview Questions
Top 50 Asp Interview Questions
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.
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.
OData
Filters
Content Negotiation
Self-Hosting
Routing
Model Bindings
1 of 10
6) What are main return types supported in Web API?
9) Web API uses which of the following open-source library for JSON
serialization?
10) By default, Web API sends HTTP response with which of the following
status code for all uncaught exception?
11) What is the biggest disadvantage of “Other Return Types” in Web API?
The biggest disadvantage of this approach is that you cannot directly return an error
code like 404 error.
2 {
4 {
2 of 10
10
11
12
13
14
15
16 };
17 return response;
18 }
19 }
20
21
22
23
24
25
For example:
Routes.MapHttpRoute(
Name: "ExampleWebAPIRoute",
routeTemplate: “api/{controller}/{id}
SOAP is an XML message format used in web service interactions. It allows to send
messages over HTTP or JMS, but other transport protocols can be used. It is also an
XML-based messaging protocol for exchanging information among computers.
3 of 10
15) What is the benefit of using REST in Web API?
REST is used to make fewer data transfers between client and server which make it an
ideal for using it in mobile apps. Web API also supports HTTP protocol. Therefore, it
reintroduces the traditional way of the HTTP verbs for communication.
16) How can we use Web API with ASP.NET Web Form?
17) How to you can limit Access to Web API to Specific HTTP Verb?
18) Can you use Web API with ASP.NET Web Form?
Yes, It is possible to use Web API with ASP.Net web form. As it is bundled with
ASP.NET MVC framework. However, it can be used with ASP.NET Web Form.
19) How Can assign alias name for ASP.NET Web API Action?
We can give alias name for Web API action same as in case of ASP.NET MVC by using
“ActionName” attribute as follows:
[HttpPost]
[ActionName("SaveStudentInfo")]
StudentRepository.AddStudent(aStudent);
TestApi is a utility library of APIs. Using this library tester developer can create
testing tools and automated tests for a .NET application using data-structure and
algorithms.
It will be executed when exceptions are unhandled and thrown from a controller
method. The reason for the exception can be anything. Exception filters will
4 of 10
implement “IExceptionFilter” interface.
[NotImplExceptionFilter]
23) How you can return View from ASP.NET Web API method?
No, we can’t return a view from ASP.NET Web API Method. Web API creates HTTP
services that render raw data. However, it’s also possible in ASP.NET MVC
application.
GlobalConfiguration.Configuration.Filters.Add(new
MyTestCustomerStore.NotImplExceptionFilterAttribute());
Config.Routes.MapHttpRoute(
);
5 of 10
27) How can you handle errors in Web API?
Several classes are available in Web API to handle errors. They are HttpError,
Exception Filters, HttpResponseException, and Registering Exception Filters.
28) What New Features comes with ASP.NET Web API 2.0?
The latest features of ASP.NET Web API framework v2.0 are as follows:
Attribute Routing
Cross-Origin Resource Sharing
External Authentication
Open Web Interface NET
HttpActionResult
Web API OData
29) How can you restrict access methods to specific HTTP verbs in Web
API?
With the help of Attributes (like HTTP verbs), It is possible to implement access
restrictions in Web API.
Example:
[HttpPost]
//logic
30) How can you pass multiple complex types in Web API?
paramList.Add(c);
paramList.Add(p);
6 of 10
32) Name the tools or API for developing or testing web api?
1. Jersey API
2. CFX
3. Axis
4. Restlet
REST is architectural style. It has defined guidelines for creating services which are
scalable. REST used with HTTP protocol using its verbs GET, PUT, POST and
DELETE.
We can perform a Unit test using Web API tools like Fiddler.
Fiddler –Compose Tab -> Enter Request Headers -> Enter the Request Body and
execute
35) How can we restrict access to methods with specific HTTP verbs in
Web API?
Attribute programming is widely used for this functionality. Web API also allows
restricting access of calling methods with the help of specific HTTP verbs. It is also
possible to define HTTP verbs as attribute over method.
[NotImplExceptionFilter]
38) Tell me the code snippet to show how we can return 404 errors from
HttpError?
7 of 10
Code for returning 404 error from HttpError
[NotImplExceptionFilter]
43) By default, Web API sends HTTP response with which of the following
status code for all uncaught exception?
In WEB API HttpError used to throw the error info in the response body.
“CreateErrorResponse” method is can also use along with this, which is an extension
method defined in “HttpRequestMessageExtension.”
GlobalConfiguration.Configuration.Filters.Add (new
MyTestCustomerStore.NotImplExceptionFilterAttribute());
Several classes are available in Web API to handle errors. They are HttpError,
8 of 10
HttpResponseException, Exception Filters, Registering Exception Filters.
WCF services use the SOAP protocol while HTTP never use SOAP protocol. That’s
why WebAPI services are lightweight since SOAP is not used. It also reduces the data
which is transferred to resume service. Moreover, it never needs too much
configuration. Therefore, the client can interact with the service by using the HTTP
verbs.
MVC framework is used for developing applications which have User Interface. For
that, views can be used for building a user interface.
WebAPI is used for developing HTTP services. Other apps can also be called the
WebAPI methods to fetch that data.
WebAPI can be consumed by any client which supports HTTP verbs such as GET,
PUT, DELETE, POST. As WebAPI services don’t need any configuration, they are very
easy to consume by any client. Infract, even portable devices like Mobile devices can
easily consume WebAPI which is certainly the biggest advantages of this technology.
50) How can we make sure that Web API returns JSON data only?
To make Web API serialize the returning object to JSON format and returns JSON
data only. For that you should add the following code in WebApiConfig.cs class in any
MVC Web API Project:
2 //JsonFormatter
3 //MediaTypeHeaderValue
4 Config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new
MediaTypeHeaderValue("application/json"));
5
1
6
2
7
3
8
//JsonFormatter
9
//MediaTypeHeaderValue
10
Config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new
11 MediaTypeHeaderValue("application/json"))
12
9 of 10
13
14
15
16
17
10 of 10