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


  • I must be missing something simple, but how is one supposed to set default extension providers for IIS hosted workflows (eg. XAMLX)?

    I want to inject a service and use it in many activities like:

    IFoo aFoo = context.GetExtension<IFoo>();

    If I were hosting it myself I would have access to a WorkflowServiceHost and at startup would do something like:

    host.WorkflowExtensions.Add<IFoo>(() => new FooImp());

    but how would I set an IFoo for my XAMLX instances to use?


    Wednesday, March 24, 2010 7:22 PM


  • Basically you use an IServiceBehavior to add the extension and a BehaviorExtensionElement to add the IServiceBehavior.


    public class StringWriterBehavior : IServiceBehavior
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
            var host = (WorkflowServiceHost)serviceHostBase;
            host.WorkflowExtensions.Add<TextWriter>(() => new StringWriter());

    public class StringWriterElement : BehaviorExtensionElement
        public override Type BehaviorType
            get { return typeof(StringWriterBehavior); }
        protected override object CreateBehavior()
            return new StringWriterBehavior();

    And the config file:

          <add name=“stringWriter“
               type="OrderService.StringWriterElement, MyWorkflowService"/>
        <service name="OrderWorkflow“
          <behavior name="OrderWorkflowBehavior">
            <serviceMetadata httpGetEnabled="True"/>
            <stringWriter />

    Wednesday, March 24, 2010 7:42 PM