InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Can we Return View from ASP.NET Web API Method? |
|
Answer» Most of the people give the wrong answer for this question. The right answer is No, we can’t. Web API does not RETURN View but returns the data. As we discussed in an earlier interview question about the difference between ASP.NET MVC and Web API, ASP.NET Web API creates HTTP SERVICES that render raw data. Although, it’s QUITE possible in ASP.NET MVC application, the APIController is meant for returning the data. So, if you need to return a view from the controller class, then make sure to use or inherit the Controller class. |
|
| 2. |
How to unit test Web API? |
|
Answer» We can unit test the WEB API using the Fiddler tool. Below are the settings to be done in Fiddler –Compose Tab -> ENTER REQUEST Headers -> Enter the Request BODY and execute. |
|
| 3. |
What are the RESTful Services? |
|
Answer» REST stands for Representational State Transfer. This term was coined by Roy Fielding in 2000. RESTful is an Architectural style for creating loosely coupled applications over HTTP. In order to make API to be RESTful, it must adhere to the around 6 constraints that are mentioned below:
This constraint specifies that a Client sends a request to the server and the server sends a response back to the client. This separation of concerns SUPPORTS the independent development of both client-side and server-side logic. That means client application and server application should be developed separately without any dependency on each other. A client should only know resource URIs and that’s all. Severs and clients may also be replaced and developed independently as long as the interface between them is not altered.
The stateless constraint specifies that the communication between the client and the server must be stateless between requests. This means that we should not be storing anything on the server related to the client. The request from the client should contain all the necessary information for the server to process that request. This ensures that each request can be treated independently by the server.
The uniform interface constraint defines an interface between the client and the server. To understand the uniform interface constraint, we need to understand what a resource is and the HTTP verbs – GET, PUT, POST and DELETE. In the context of a REST API, resources typically represent data entities. The product, Employee, Customer, etc. are all resources. The HTTP verbs (GET, PUT, POST, and DELETE) that are sent with each request tell the API what to do with the resource. Each resource is identified by a specific URI (Uniform Resource Identifier).
Some data provided by the server like the list of products, or list of departments in a company does not change that often. This constraint lets the client know how long this data holds good, so that the client does not have to come back to the server for that data over and over again.
|
|
| 4. |
Explain the difference between WCF vs MVC vs ASP.NET Web API ? |
|
Answer» WCF
Web API
MVC
|
|
| 5. |
When to prefer ASP.NET Web API over WCF? |
|
Answer» It completely depends upon the requirement. Choose ASP.NET WEB API if you want 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 WCF, but that requires a lot of CONFIGURATION. In case you want a service that should support multiple transport protocols like HTTP, UDP, TCP, ETC. then WCF will be the better option. |
|
| 6. |
What is REST and RestFul? |
|
Answer» REST or Representational State Transfer is an architectural style for designing applications. Instead of using complex MECHANISMS like CORBA, RPC or SOAP for communication, it dictates that HTTP should be used. There are a few principles associated with REST architectural style:
RESTFUL: It is TERM written by applying REST architectural concepts and is called RESTful services. It focuses on system resources and how the state of the resource should be transported over HTTP protocol. |
|
| 7. |
Which .NET Framework supports ASP.NET Web API? |
|
Answer» First VERSION of ASP.NET WEB API is introduced in .NET Framework 4. After that, all the later versions of the .NET Framework support the ASP.NET Web API. |
|
| 8. |
What are the differences between REST and SOAP? |
|
Answer» The difference between REST and SOAP is given below:
|
|
| 9. |
Is it true that ASP.NET Web API has replaced WCF? |
|
Answer» It’s a misconception that ASP.NET Web API has replaced WCF. It’s another way of building non-SOAP based services, for example, PLAIN XML or JSON string etc. Yes, it has some ADDED advantages like utilizing full features of HTTP and reaching more clients such as mobile devices etc. But WCF is still a good choice for the following scenarios:
|
|
| 10. |
Compare WCF vs ASP.NET Web API and state the differences with advantages and disadvantages? |
||||||||||||||||||||||||||||||||||||
|
Answer» Windows Communication Foundation is designed to exchange standard SOAP-based messages using a variety of transport protocols like HTTP, TCP, NamedPipes or MSMQ, etc. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocols like HTTP, TCP, MSMQ, etc. WCF ships out with the .NET Framework. WCF service is good for Message Queue, duplex communication, one-way messaging. WCF supports SOAP and XML formats. ASP.NET API is a framework for building non-SOAP based services over HTTP only. 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. One major advantage of Web API is that it is the best fit with MVC PATTERN. Web API supports any media format including JSON, XML.
|
|||||||||||||||||||||||||||||||||||||
| 11. |
What are the Advantages of Using ASP.NET Web API? |
|
Answer» Using ASP.NET Web API comes with a number of advantages, the core advantages being:
|
|
| 12. |
What is XML & JSON? |
|
Answer» XML stands for eXtensible Markup Language. It is a markup language like HTML and is DESIGNED to store and transport data. XML doesn’t do anything, but it can store data in a SPECIFIC format. JSON stands for JavaScript Object Notation and is also used to store and transport data. JSON is often used when data is sent from a SERVER to a web PAGE. JSON is "self-describing" and easy to understand. JSON is a lightweight format for storing and transporting data. |
|
| 13. |
What is the difference between WCF Rest and Web API? |
|||||||||
|
Answer» It is difficult to say which one is better between Web API and WCF Rest service. Both the TECHNOLOGIES have their own significant in the context of development, hosting and consuming the service.Although both WCF REST and ASP.NET Web API follow the REST architecture, these have the following differences: WCF Rest
Web API
|
||||||||||
| 14. |
What are Internet Media Types? |
|
Answer» Media Type is a file identification mechanism on the MIME encoding system, formerly “MIME type”. The Internet media type has become the de facto standard for IDENTIFYING CONTENT on the Internet. For example, consider an instance of RECEIVING an email from a server with an attachment, the server embeds the media type of the attachment in the message header. So, the browser can launch the appropriate helper APPLICATION or plug-in. |
|
| 15. |
What is HTTP Content |
|
Answer» HTTP header fields are components of the header SECTION of request or RESPONSE messages in the Hypertext Transfer Protocol. It defines the OPERATING parameters of an HTTP transaction. There are more contents in an HTTP header field. For example, HTTP request to fetch aspnetwebapi.htm PAGE from the web server running on developmenthelp.net. |
|
| 16. |
What are HTTP Status Codes? |
|
Answer» HTTP Status Codes are the 3 digit integers which contain in server response. There is a meaning for each number. Response Header of each API response contains the HTTP Status Code. The first digit of the Status-Code defines the class of response. HTTP Status Codes are grouped into five categories based upon the first number. Following are the SET of status codes with its meaning:
Some of the commonly seen HTTP Status Codes are: 200 (Request is Ok), 201 (Created), 202 (Accepted), 204 (No Content), 301 (Moved Permanently), 400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 500 (Internal Server Error), 502 (Bad Gateway), 503 (Service Unavailable) etc. |
|
| 17. |
What are different HTTP Methods? |
|
Answer» There are various types of HTTP methods and they can be used according to the requirements. These methods are case-sensitive and they must used in UPPERCASE.
AMONG these methods GET/PUT/POST/DELETE are the most popular methods. |
|
| 18. |
What are Resources and URIs? |
|
Answer» URI is a string of characters used to identify a resource on the INTERNET either by location or by name, or by both. URI stands for Uniform Resource Identifier. URI is used to identify resources, for example, in the real world assume there is a person named “TEST Person” who lives in “403, Test City, World”. We can find that person by address or by name or by both. URI can be categorized into 2 as URL and URN
URI is used to send requests to the server. This can be ACHIEVED with the help of both URN and URL. Using URN is inefficient, as there can be many resources with the same name. So the most widely used method is URL. URL consists of two required components The Protocol & The Domain. Look at the FOLLOWING URL: http://www.testname.net/asp-net-webapi Here the red colored part is the protocol and the BLACK colored part is the domain, other parts are optional. It may contain the port/path/query strings/fragments. |
|
| 19. |
Who can consume WebAPI? |
|
Answer» The clients which support HTTP VERBS such as GET, PUT, DELETE, POST consume WebAPI services. As WebAPI services are very easy to consume by any client because they don’t need any CONFIGURATION. PORTABLE devices LIKE Mobile devices, IoT can easily consume WebAPI which is certainly the biggest advantages of this technology. |
|
| 20. |
What is ASP.NET Web API and what are its advantages? |
|
Answer» ASP.NET Web API is a framework provided by the Microsoft open source technology for building and consuming HTTP based services on top of .NET Framework. The advantage of Web API is that it can be consumed by a broader range of clients including web browser and mobile applications, IoT etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework. So there will be a client server communication using HTTP protocol. HTTP (Hypertext Transfer Protocol) is an application level protocol that is USED to deliver data such as html files, IMAGE files, query results, etc. on the World Wide Web. HTTP is a stateless protocol, meaning that after one cycle of request and response the server forgets everything about the cycle, and it considers another request from the same client as a new request from a new client. Below is a simple Client-Server architecture of HTTP protocol Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings, etc. with many other ADVANTAGES including:
|
|