Self Hosted WCF Applications
  • 1 Minute to read
  • Dark
  • PDF

Self Hosted WCF Applications

  • Dark
  • PDF

Article Summary

Retrace automatically supports WCF transactions that are hosted within an IIS application. If you are "self hosting" WCF in a Windows Service or similar background app, 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 WCF Inspector nuget package to your application

A WCF inspector needs to be added to your code and can be installed via a nuget package. This inspector allows Retrace to recognize when transactions begin and end.  Find the nuget package download here: Stackify WCF Inspector

Via nuget:

Install-Package StackifyWCFInspector

Step 3. Configure the WCF Inspector

Note: Configuring the WCF inspector can be done 3 different ways, but only do one of them!

Option 1: Modify app.config to add the extension via config

Example below just shows the pieces you need to add to your existing config. Add the behaviorExtension and then use it further down as a behavior.

        <add name="stackifyInspector" type="StackifyWCFInspector.StackifyBehaviorExtensionElement, StackifyWCFInspector"/>
          <stackifyInspector />

Option 2: Use attribute on your WCF class

public class MyMathService : IMyMathService
  //your methods...
  public double Add(double dblNum1, double dblNum2)
	  return (dblNum1 + dblNum2);

Option 3: Add the inspector behavior before the ServiceHost starts:

var host = new ServiceHost(typeof (MyMathService));
foreach (var endpoint in host.Description.Endpoints)
	endpoint.Behaviors.Add(new StackifyWCFInspector.MessageInspector());

Was this article helpful?