Explore topic-wise InterviewSolutions in .

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.

How To Handle Errors In Web Api?

Answer»

SEVERAL classes are AVAILABLE in Web API to handle errors. They are HTTPERROR, HttpResponseException, Exception Filters, REGISTERING Exception Filters.

Several classes are available in Web API to handle errors. They are HttpError, HttpResponseException, Exception Filters, Registering Exception Filters.

2.

How Can We Register Exception Filter Globally?

Answer»

We can register exception filter GLOBALLY using following CODE:

GlobalConfiguration.Configuration.Filters.Add(NEW MyTestCustomerStore.NotImplExceptionFilterAttribute());

We can register exception filter globally using following code:

GlobalConfiguration.Configuration.Filters.Add(new MyTestCustomerStore.NotImplExceptionFilterAttribute());

3.

How Can We Register Exception Filter From Controller?

Answer»

We can register exception filter from CONTROLLER USING following code:

[NotImp ExceptionFilter]

PUBLIC class TEST CustomerController : Controller

{

// WRITE the code

}

We can register exception filter from controller using following code:

[NotImp ExceptionFilter]

public class Test CustomerController : Controller

{

// write the code

}

4.

How Can We Register Exception Filter From Action?

Answer»

We can register exception filter from ACTION USING following code 

[NotImp ExceptionFilter]

public Test CUSTOMER Get My Test Customer(in custid)

{

//WRITE the code

}

We can register exception filter from action using following code 

[NotImp ExceptionFilter]

public Test Customer Get My Test Customer(in custid)

{

//write the code

}

5.

How Can We Register Exception Filters?

Answer»

Three options are available to register EXCEPTION Filters which are From ACTION, From CONTROLLER and Global REGISTRATION.

Three options are available to register Exception Filters which are From Action, From Controller and Global registration.

6.

What Are Exception Filters?

Answer»

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.

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.

7.

What Is Testapi?

Answer»

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.

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.

8.

Differentiate Between Wcf And Web Api?

Answer»

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.

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.

9.

What Are The Advantages Using Webapi?

Answer»
  • 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

10.

Web Api Where Is The Proxy?

Answer»

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.

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.

With Wcf Also You Can Implement Rest, So Why Webapi?

Answer»
  • 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.

12.

What Are The Advantages Of Using Rest In Web Api?

Answer»
  1. REST used to make less data transfers between CLIENT and server.
  2. Web API SUPPORTS HTTP protocol VERBS for communication.

13.

Differences Between Wcf And Web Api?

Answer»

WCF : 

  1. WCF is a framework USED for build/develop service oriented applications. 
  2. WCF can be CONSUMED by clients which can understand XML. 
  3. WCF supports wide range of PROTOCOLS like HTTP, TCP, Named Pipes and more.
  4. For each method there has to be attributes like – “WebGet” and “WebInvoke”
  5. For REST service we need to use attribute “WebInvoke”.

Web API:

  1. Web API is a framework used to build/develop HTTP based services.
  2. Web API is an open source platform.
  3. It supports only HTTP protocol.
  4. Web API can be hosted in IIS or in application.
  5. UNLIKE WCF Rest we can use full features of HTTP in Web API
  6. This returns XML or JSON to client.

WCF : 

Web API:

14.

What Is Web Api Routing?

Answer»

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}

};

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}

};

15.

How To Restrict Access To Methods With Specific Http Verbs In Web Api?

Answer»

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

 }

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

 }

16.

Can Web Api Return View In Mvc?

Answer»

We cannot RETURN VIEW from WEB API.

We cannot return view from Web API.

17.

Can We Do Unit Test Web Api?

Answer»

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.

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.

18.

What Is Web Api?

Answer»

Unlike WCF service WEB API is a FRAMEWORK which is used to build/develop HTTP based SERVICES.

Unlike WCF service Web API is a framework which is used to build/develop Http based services.