.NET Framework Developer Center > .NET Development Forums > Windows Workflow Foundation > Hosting WorkflowService (WorkflowRuntime) in IIS using WCF
Ask a questionAsk a question
 

AnswerHosting WorkflowService (WorkflowRuntime) in IIS using WCF

  • Monday, February 12, 2007 12:47 PMslein Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I'd like to host some kind workflow service (using Windows Workflow Foundation) within the IIS. Therefore I have configured a service file (.svc) and an appropriate web.config file.

    When the service starts (managed by IIS?) it should load the WorkflowRuntime instance. Therefore I've created a class implementing the IExtension<ServiceHostBase> interface holding that instance.
    Because my application is not directly responsible for creating the ServiceHost (-> IIS) - how can I add this extension to the service host? Is it possible to configure this via the web.config file (<extensions>-Element)? Or do I have to write such a class inheriting from ServiceHostFactoryBase and configuring the service file?

    Thank you!

Answers

  • Friday, February 23, 2007 4:07 PMJörg Jooss - MSFTMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    That's a WCF question, not a WF question .

    You can either attach the IExtension using a custom ServiceHostFactory, or inject it using a IServiceBehavior. The latter approach can be implemented using an attribute that you can attach to your service implementation:

    [WorkflowBehavior]
    public class MyWorkflowEnabledService : IMyWorkflowEnabledService
    {
       //...
    }
      

    There's also a new whitepaper on integrating WCF and WF.

     

All Replies

  • Friday, February 23, 2007 2:23 PMChristophe De Langhe Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Did you ever found the solution for this ?
  • Friday, February 23, 2007 4:07 PMJörg Jooss - MSFTMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    That's a WCF question, not a WF question .

    You can either attach the IExtension using a custom ServiceHostFactory, or inject it using a IServiceBehavior. The latter approach can be implemented using an attribute that you can attach to your service implementation:

    [WorkflowBehavior]
    public class MyWorkflowEnabledService : IMyWorkflowEnabledService
    {
       //...
    }
      

    There's also a new whitepaper on integrating WCF and WF.

     

  • Friday, February 23, 2007 7:46 PMChristophe De Langhe Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    What I am doing now is the following: when I need the workflow runtime I am going to check if I have an extension, if not I create one. From then on I will reuse this one until my extension is shut down.

    private WorkflowRuntime myWFRuntime
    {
     get
     {
         myExtension ext ;
         if (OperationContext.Current.Host.Extensions.Find<myExtension>()==null)
         {
             ext = new myExtension();
             OperationContext.Current.Host.Extensions.Add<myExtension>(ext);
             return ext.WorkFlowRuntime;
         }
         else
            return OperationContext.Current.Host.Extensions.Find<myExtension>().WorkFlowRuntime;
     }

    }

     

    Is this a correct approach ?

  • Monday, February 26, 2007 8:45 AMJörg Jooss - MSFTMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    That might be problematic due to race conditions — I don't think that ServiceHostBase.Extensions collecition is tread-safe. Attaching the workflow runtime during service activation is IMHO a better design.