state machine receive activity not working RRS feed

  • Question

  • Very Confused!

    I am running a state machine from Silverlight through a WCF service.  From Silverlight instantiate a client from the proxy class and start the workflow:


    I can step into the proxy (BeginStartWorkflow) and see the proper applicationDetail GUID passed in and the Start works fine.  I have my persistance service all hooked up in the runtime and set UnloadOnIdle = true. I can see polling calls to the database so i know its running.  It seems that the receive activity in the workflow
    is ignoring the GUID passed in StartWorkflowAsync!

    When I hit the event below I get an error.  I added the e.WorkflowInstance.Unload() to try and force persistence.

    void runtime_WorkflowIdled(object sender, WorkflowEventArgs e)
                Debug.WriteLine("Workflow runtime Idled");

    this is the error:

    System.InvalidOperationException was unhandled by user code
      Message="The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance \"17f751fe-8f1b-4fcf-b046-6fee70f8f498\"."
           at System.Workflow.Runtime.WorkflowInstance.Unload()
           at CIEE.Silverlight.Polaris.Workflow.CustomWorkflowServiceHost.runtime_WorkflowIdled(Object sender, WorkflowEventArgs e) in C:\Code\Polaris\CIEE.Silverlight.Polaris.Workflow\CustomWorkflowServiceHost.cs:line 103
           at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
           at System.Workflow.Runtime.WorkflowRuntime.OnIdle(WorkflowExecutor executor)

    The Guid in the error is not the Guid passed into the Receive activity.  It instantiated a workflow but gave it a new Guid.  What am i missing?

    Thanks for any help!!

    Thursday, July 23, 2009 7:18 PM


  • OK I think I know what the problem is.  Remeber this is a Silverlight app using a WCF service to call the workflow.

    I created a custom WorkflowServiceHostFactory that inherits from the base class and repointed my .svc file to use it; credit to Abhijeet patel's blog at


    This allowed me to hit break points for runtime events.  I noticed that when the runtime_WorkflowUnloaded event was hit the WorkflowEventArgs contained two runtimes, the one I configured for persistance in the Global.aspx of the Silverlight app and added to the Application object on App Start.  The other runtime was spawned by the Receive activity (at least I think this is the case).  This is the one the workflow is using and it is not configured for persistence resulting in the error.  If I configure this runtime in my custom WorkflowServiceHostFactory for persistence it works.

    If this were a normal asp.net app I think the Application["WFRuntime"] is used by default.

    Some questions:
    1.  Do all receive activities spawn wf runtimes?
    2.  In a Silverlight app is it not possible to use the Application["WFRuntime"]?
    3.  Why can't I add a ManuelWorkflowSchedulingService to runtime created in my custom class? This causes an error at runtime.

    Any help is greatly appreciated!


    Friday, July 24, 2009 1:38 PM