locked
WorkflowRuntime accessing if WF is hosted on IIS RRS feed

  • Question

  • We are hosting WF on IIS and AppFabric.

    How can I access WorkflowRuntime from code if this is hosting enviroment.

    Actually, I'm trying to hook on WorkflowPersisted event and only way I found is using WorkflowRuntime.

     

    Thanks,

    Mladen

    Thursday, December 30, 2010 2:51 PM

Answers

  • Hi! i don't know what are you trying to do exactly, but maybe you can try with PersistenceParticipant.. http://msdn.microsoft.com/en-us/library/system.activities.persistence.persistenceparticipant.aspx i hope it helps... cheers from argentina!
    Pablo Rotondo http://www.datapayasadas.com.ar
    • Marked as answer by Andrew_Zhu Monday, January 10, 2011 7:39 AM
    Friday, January 7, 2011 5:41 PM
  • Hi, Mladen

    WorkflowRuntimeBehavior is for WF3/3.5. so you won't find it in WF4. When you write this class, there are some tricky to use the right namespace. here is the full code:

    using System;
    using System.Collections.Generic;
    using System.Workflow.Activities;
    using System.Activities;
    using System.Workflow.Runtime;
    using System.ServiceModel.Activities.Activation;
    using System.ServiceModel.Activities;
    using System.ServiceModel.Description;
    using System.Activities.DurableInstancing;
    using System.Configuration;

    namespace Xhinker.WF4.MyXamlxFactory {
        public class MyServiceHostFactory : System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory {
            protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, 
                                                                             Uri[] baseAddresses) {
                WorkflowServiceHost host = base.CreateWorkflowServiceHost(service, baseAddresses);
                string connectionString = ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();
                host.DurableInstancingOptions.InstanceStore = new SqlWorkflowInstanceStore(connectionString);
                return host;
            }

            private SqlWorkflowInstanceStore SetupSimplySqlPersistenceStore() {
                string connectionString =
                    ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();
                SqlWorkflowInstanceStore sqlInstanceStore =
                    new SqlWorkflowInstanceStore(connectionString);
                sqlInstanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30);
                return sqlInstanceStore;
            }
        } 
    }
    Note that this code runs well in IIS, have not test in Appfabric.
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Monday, January 10, 2011 7:39 AM
    Tuesday, January 4, 2011 2:09 AM

All replies

  • Hi, Mladen

    To use your own workflow host in IIS, you can create your own ServiceHostFactory and add it in Web.config file.
    This sample I created would be helpful to you:

    Create Your Own ServiceHostFactory
    http://xhinker.com/post/WF4Create-Your-Own-ServiceHostFactory.aspx

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Monday, January 3, 2011 2:48 AM
  • I've created factory but I couldn't access runtime since there is no WorkflowRuntimeBehavior in ServiceHostBase.Description.Behaviors. Here is a code snippet.

     public class MyServiceHostFactory : WorkflowServiceHostFactory {
      public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses) {
       ServiceHostBase sh = base.CreateServiceHost(constructorString, baseAddresses);
       WorkflowRuntimeBehavior wrb = sh.Description.Behaviors.Find<WorkflowRuntimeBehavior>();
       wrb.WorkflowRuntime.WorkflowIdled += new EventHandler<WorkflowEventArgs>(WorkflowRuntime_WorkflowIdled);
       return sh;  
    	}
    	//.....
    }

    Thanks,

    Mladen

     

    Monday, January 3, 2011 2:44 PM
  • Hi, Mladen

    WorkflowRuntimeBehavior is for WF3/3.5. so you won't find it in WF4. When you write this class, there are some tricky to use the right namespace. here is the full code:

    using System;
    using System.Collections.Generic;
    using System.Workflow.Activities;
    using System.Activities;
    using System.Workflow.Runtime;
    using System.ServiceModel.Activities.Activation;
    using System.ServiceModel.Activities;
    using System.ServiceModel.Description;
    using System.Activities.DurableInstancing;
    using System.Configuration;

    namespace Xhinker.WF4.MyXamlxFactory {
        public class MyServiceHostFactory : System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory {
            protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, 
                                                                             Uri[] baseAddresses) {
                WorkflowServiceHost host = base.CreateWorkflowServiceHost(service, baseAddresses);
                string connectionString = ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();
                host.DurableInstancingOptions.InstanceStore = new SqlWorkflowInstanceStore(connectionString);
                return host;
            }

            private SqlWorkflowInstanceStore SetupSimplySqlPersistenceStore() {
                string connectionString =
                    ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();
                SqlWorkflowInstanceStore sqlInstanceStore =
                    new SqlWorkflowInstanceStore(connectionString);
                sqlInstanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30);
                return sqlInstanceStore;
            }
        } 
    }
    Note that this code runs well in IIS, have not test in Appfabric.
    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    • Marked as answer by Andrew_Zhu Monday, January 10, 2011 7:39 AM
    Tuesday, January 4, 2011 2:09 AM
  • I understand your code and thanks for answering but I'm not sure how can I use it.

    What I need is to fire custom action before workflow instance goes to sleep and after it wakes up. Not sure how can I do this using code provided.

     

    Thanks!

     

    Tuesday, January 4, 2011 8:37 AM
  • Hi, Mladen

    Since the workflow services are running on host created by yourself. you can subscribe events to host for example:
                        host.Opening += (obj, arg) => {
                            //your code
                        };
    Regards


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Thursday, January 6, 2011 5:55 AM
  • Hi! i don't know what are you trying to do exactly, but maybe you can try with PersistenceParticipant.. http://msdn.microsoft.com/en-us/library/system.activities.persistence.persistenceparticipant.aspx i hope it helps... cheers from argentina!
    Pablo Rotondo http://www.datapayasadas.com.ar
    • Marked as answer by Andrew_Zhu Monday, January 10, 2011 7:39 AM
    Friday, January 7, 2011 5:41 PM