views:

233

answers:

1

I'm having touble trying to attach a custom tracking participant in workflow foundation 4.0. I have a class that inherits from TrackingParticipant but I cannot see any other way of attaching it to my WorkflowServiceHost other than through lots of messy app.config entries like the SDK example demonstrates below (in the system.servicemodel element). This option seems to require a lot of extra overhead and classes to be created, when I just want a simple custom tracking participant to listen to my CustomTrackingRecord.Data.Add(key, value) calls.

public class CustomTracking : TrackingParticipant
{
    protected override void Track(TrackingRecord record, TimeSpan timeout)
    {
        CustomTrackingRecord innerRecord = (CustomTrackingRecord)record;
        var workflowInstanceId = innerRecord.InstanceId;

        Console.WriteLine("Track called for workflow '{0}'", workflowInstanceId);
    }
}

How can I register my above custom tracking participant through code (and not config like below) to a workflowServiceHost instance?

Many thanks!

      <extensions>
    <behaviorExtensions>
      <add name="historyFileTracking" type="Microsoft.Samples.HistoryFileTrackingExtensionElement, HiringRequestProcessDefinition, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />     
    </behaviorExtensions>
  </extensions>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <historyFileTracking profileName="RequestStoryTracking" path="..\..\..\Data\RequestHistory\"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <tracking>
    <profiles>
      <trackingProfile name="RequestStoryTracking">
        <workflow activityDefinitionId="*">
          <customTrackingQueries>
            <customTrackingQuery name="*" activityName="*" />
          </customTrackingQueries>
        </workflow>
      </trackingProfile>
            </profiles>
  </tracking>
+1  A: 

Just add it as a workflow extension to the WorkflowServiceHost.

var host = new WorkflowServiceHost(....);
var tracker = new CustomTracking();
host.WorkflowExtensions.Add(tracker);
host.Open();
Maurice