-
1. What Is Web Api?
Unlike WCF service Web API is a framework which is used to build/develop Http based services.
-
2. What Is Rest?
- REST stands for Representational state transfer.
- It is a architectural style, which defines rules for creating scalable services.
- REST is works on HTTP protocol using its verbs GET, POST, PUT and DELETE.
-
3. Can We Do Unit Test Web Api?
Web API can be unit test by using Fiddler tool.
Following is the settings to be updated in Fiddler:
Compose Tab -> Enter Request Headers -> Enter the Request Body and execute.
-
4. Can Web Api Return View In Mvc?
We cannot return view from Web API.
-
5. How To Restrict Access To Methods With Specific Http Verbs In Web Api?
With the help of Attributes(like http verbs) one can implement access restrictions in Web API.
We can define HTTP verbs as attribute over method to restrict access.
Example :
[HttpPost]
public void SampleMethod(SampleClass obj)
{
//logic
}
-
6. What Is Web Api Routing?
Routing is nothing but pattern matching like in MVC.
All routes will get registered in Route Tables.
Example :
Routes.MapHttpRoute(
Name: “SampleWebAPIRoute”,
routeTemplate: “api/{controller}/{id}
defaults: new { id = RouteParameter.Optional}
};
-
7. Differences Between Wcf And Web Api?
WCF :
- WCF is a framework used for build/develop service oriented applications.
- WCF can be consumed by clients which can understand XML.
- WCF supports wide range of protocols like HTTP, TCP, Named Pipes and more.
- For each method there has to be attributes like – “WebGet” and “WebInvoke”
- For REST service we need to use attribute “WebInvoke”.
Web API:
- Web API is a framework used to build/develop HTTP based services.
- Web API is an open source platform.
- It supports only HTTP protocol.
- Web API can be hosted in IIS or in application.
- Unlike WCF Rest we can use full features of HTTP in Web API
- This returns XML or JSON to client.
-
8. What Are The Advantages Of Using Rest In Web Api?
- REST used to make less data transfers between client and server.
- Web API supports HTTP protocol verbs for communication.
-
9. With Wcf Also You Can Implement Rest, So Why Webapi?
- WCF was brought in to implement SOA, never the intention was to implement REST.
- Web API is built from Scratch and the only goal is to create HTTP services using REST.
-
10. Web Api Where Is The Proxy?
Web API doesn’t make it easy for consumers to generate a service client like a SOAP WSDL does. If you’re only ever going to have .NET clients it’s not a big deal because they can share the contract objects you implement, but other language clients will need to manually create their client objects if you don’t use SOAP.
-
11. What Are The Advantages Using Webapi?
- OData support (via Queryable attribute)
- Content Negotiation
- Filters
- Model binding and validation
- Ability to self host outside of IIS
- Link generation to related resources that incorporates routing rules
- Full support for routes/routing
- Ability to create custom help and test pages using ApiExplorer
-
12. Differentiate Between Wcf And Web Api?
WCF –
Windows Communication Foundation(WCF) has been created by Microsoft with .NET Framework 3.0. It supports SOAP based services. It has compatibility with HTTP, TCP, UDP, etc. Good for developing secure and interoperable services. Used for back end purposes.WEB API –
Web API open source framework. It has compatibility with HTTP only. It has a support for non-SOAP based services. It is very light weight hence good for developing services for low bandwidth devices. It supports OData. It supports most of the MVC features. Used for front end purposes. -
13. What Is Testapi?
TestApi is a library of utility and test APIs through which testers and developers create testing tools and automated tests for .NET and Win32 application using data-structure and algorithms.
-
14. What Are Exception Filters?
Exception filters will be executed when some of the exceptions are unhandled and thrown from a controller method. The reason for the exception may be anything. Exception filters will implement “Exception Filter” interface.
-
15. How Can We Register Exception Filters?
Three options are available to register Exception Filters which are From Action, From Controller and Global registration.
-
16. How Can We Register Exception Filter From Action?
We can register exception filter from action using following code
[NotImp ExceptionFilter]
public Test Customer Get My Test Customer(in custid)
{
//write the code
}
-
17. How Can We Register Exception Filter From Controller?
We can register exception filter from controller using following code:
[NotImp ExceptionFilter]
public class Test CustomerController : Controller
{
// write the code
}
-
18. How Can We Register Exception Filter Globally?
We can register exception filter globally using following code:
GlobalConfiguration.Configuration.Filters.Add(new MyTestCustomerStore.NotImplExceptionFilterAttribute());
-
19. How To Handle Errors In Web Api?
Several classes are available in Web API to handle errors. They are HttpError, HttpResponseException, Exception Filters, Registering Exception Filters.
ASP.NET Interview Questions
ASP.NET Tutorial
Framework7 Interview Questions
Framework7 Tutorial
HTTP Interview Questions
Windows Communication Foundation (WCF) Interview Questions
HTTP Tutorial
Java XML Interview Questions
ASP.NET Interview Questions
Windows Communication Foundation (WCF) Tutorial
JSON (JavaScript Object Notation) Interview Questions
Java XML Tutorial
Oracle iPlanet Web Server (OiWS) Interview Questions
Framework7 Interview Questions
JSON (JavaScript Object Notation) Tutorial