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

Self Hosted WCF Applications

  • Dark
    Light
  • 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.

 <system.serviceModel>
    <extensions>
      <behaviorExtensions>
        <add name="stackifyInspector" type="StackifyWCFInspector.StackifyBehaviorExtensionElement, StackifyWCFInspector"/>
      </behaviorExtensions>
    </extensions>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <stackifyInspector />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

Option 2: Use attribute on your WCF class

[StackifyWCFInspector.StackifyInspectorBehavior]
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());
}
svcHost.Open();   

Was this article helpful?