Self Hosted Web API
  • 1 Minute to read
  • Dark
    Light
  • PDF

Self Hosted Web API

  • Dark
    Light
  • PDF

Article Summary

Retrace automatically supports Web API transactions that are hosted within an IIS application. If you are "self hosting" Web API in a Windows Service, please use these directions.

Step 1. Configure Retrace to know about and profile your application

By default Retrace only profiles IIS applications. Please review this article on how to tell it to profile your application: .NET Agent Installation: Configure Windows Services

Step 2. Add the Stackify Web API Message Handler nuget package to your application

Web API can be self hosted in a Windows Service or console app, outside of IIS. A Message Handler needs to be added to your code and can be installed via a nuget package. This Message Handler allows Retrace to recognize when transactions begin and end.  Find the nuget package download here: Stackify Web API Message Handler

Via nuget:

Install-Package StackifyWebApiMessageHandler

Your code will look similar to the example below. You only need to add our Message Handler.

public void Configuration(IAppBuilder app)
{
    // Your code sort of looks like this in Startup.cs but probably much more complicated
    var config = new HttpConfiguration();
    config.MessageHandlers.Add(new StackifyWebApiMessageHandler.RequestTracer()); <-- add this line
    app.UseWebApi(config);
}

Was this article helpful?