Trace execution path in asp.net Web API

Hi,

In the below post we are going to see that how we can trace an asp.net Web API execution path for any request and see what processing path it is following internally .

For that your project should have “Microsoft.AspNet.WebApi.Tracing” package installed .You can install it using NuGet package manager , other

alternatives are install Asp.Net and Web Tools 2012.2 . below is the link of Scott blog which have information about the link.

http://weblogs.asp.net/scottgu/archive/2012/12/14/announcing-the-asp-net-and-web-tools-2012-2-release-candidate.aspx

Now , we are going to use the “Microsoft.AspNet.WebApi.Tracing” package to enable the tracing for your Web API project.

Open your Web API project and go to Tools—>Library Package Manager—>Package Manager Console and click on it.

image

it will open package manager console as below.

image

Now on the console, type “Install-Package Microsoft.AspNet.WebApi.Tracing” and press Enter (Make sure you connected to internet) . it will generate the information much similar

to below and install the package.

image

Now the tracing package is installed on your project after successful installation it will open a readme.txt file which gives information about “Microsoft ASP.NET Web API Tracing” .

image

You can see the readme file gives clear information about how to enable tracing. below is the line of code which does this magic.

config.EnableSystemDiagnosticsTracing();

since we are using the Web API project template so we need to add the above line in the Register method of WebApiConfig.cs or vb file which you can

find on App_Start directory.

image

add the code as below.

image

Now we are ready to trace. As a sample I am using Web API ValuesController class .

Clear your Visual studio Output Window and Call the Values controller class method by passing the “10” as parameter

image

Now go to the Output Window again , you can see that it generated useful piece of information about how your request processed under Web API .

image

You can investigate these information for further information about your methods execution path, how the values get bind , Which class is doing what etc.

Hope you find this post useful , thanks for reading 🙂

Technorati Tags:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s