WorkflowServiceHost WorkflowExtensions RRS feed

  • Question

  • Is there some documentation on WorkflowExtensions for Beta 2?  In Beta 1 I had a ServiceHostExtension which did my persistence on idle, as well as provided some other useful things like recording exceptions thrown in a workflow.   I see the WorkflowServiceHost has a new WorkflowExtensions collection, but what base class do I need to override to create one, and is this the replacement for ServiceHostExtension?
    Tuesday, October 20, 2009 4:30 PM

All replies

  • To elaborate, I would like to know exactly what abstract classes that I can implement which are for Extensions.  Specifically, if possible, something that would give me access to the WorkflowInstance that is currently executing, and it's events.  Since Extensions.Add() takes an object, it's hard for me to guess.

    I've already figured out that you can add a TrackingParticipant.  Can someone shed some light here? :)
    Tuesday, October 20, 2009 6:00 PM
  • Hi there.
    Extentions can be used to provide functionality or context information for the workflow.  With WorkflowApplication, this is done via the Extensions.Add method.  With WorkFlowServiceHost you add via the Host.WorkflowExtensions.Add method.
    As you mentioned, there is a TrackingParticipant.  There's also the PersistenceParticipant. 
    If you want to make your extension available to all activities and shared by all instances within the host, you can use the Host.WorkflowExtensions.Add(object singleton) method.
    If you want to have your extension created for every instance as it's created or loaded, use the  
    Add<T>(Func<T> func) method.
    That may look something like this:
    Host.WorkflowExtensions.Add<MyExtension>(() => new MyExtension());

    There is no abstract base class you need to implement.  It's just an object.
    Hope that helps.
    MS Developer Support
    Tuesday, October 20, 2009 7:05 PM
  • Thanks Scott.  I've dugg a little deeper with reflector, and this extensions collection is indeed very cool, especially for NativeActivity's.  For example, the WriteLine activity will look and see if there is a TextWriter extension, and if there is one, it will write to that instead of the console.  This could be extremely useful.  What I was trying to do was to write the glue code to automatically persist a workflow after it was idle, because I had to do this myself with WorkflowServiceHost in Beta 1.  I've found the WorkflowIdleBehavior and this now accomplishes this.  Also, I created a simple Console tracking participant to help me monitor a workflow being created, resumed, idled, and unloaded.    Here is the code to my Console TrackingParticipant, hopefully it will be useful to some of you guys:

        public class ConsoleTracker : TrackingParticipant
            protected override void Track(TrackingRecord record, TimeSpan timeout)
                if (record is WorkflowInstanceRecord)
                    WorkflowInstanceRecord r = record as WorkflowInstanceRecord;
                    Console.WriteLine("{0} - {1} - {2} - {3}", record.EventTime.ToString(), r.ActivityDefinitionId, r.State, record.InstanceId);
                else if (record is BookmarkResumptionRecord)
                    BookmarkResumptionRecord r = record as BookmarkResumptionRecord;                
                    Console.WriteLine("{0} - {1} - {2}",record.EventTime.ToString(),r.Owner.Name, "BookmarkResumed");
                    Console.WriteLine("\tName: {0}", r.BookmarkName);
                    Console.WriteLine("\tObjectType: {0}", r.Payload.GetType().Name);
                else if (record is ActivityStateRecord || record is ActivityScheduledRecord)
                    //silence please
                    Console.WriteLine("{0} - {1} ", record.Level, record.GetType().Name);            
    Tuesday, October 20, 2009 8:01 PM
  • Scott;

    How would one do this in a WF-WCF Service App in the web.config?

    For Example converting the WCF vs2010 .NET 4.0 Example HiringRequestSystem from a console app to a IIS hosted app the line:

    host.WorkflowExtensions.Add(new HiringRequestInfoPersistenceParticipant());

    Would convert to what in the web.config for xamlx service?

    I thought it would be something like:

            <add name="PersistanceParticipant" type="Microsoft.Samples.HiringService, myAssembly" />

    but that does not work because the class inherits from

    and not behaviorExtension
    I could use some help on this!!! Thanks In Advance!!!
    Tuesday, June 15, 2010 2:05 PM
  • Hi JManley,

    In case you didn't find an answer yet please see the code in this other thread.

    "Using Workflow Extensions (context.GetExtension) in IIS-hosted workflows"


    Tuesday, June 22, 2010 5:48 PM