Retrieving current state

I am running an ASP.NET site using WWF, I've chosen to implement a StateMachineWorkflow.

In several samples I've seen, navigation between pages is done by Repsonse.Redirect(). In stead of using this mechanism (which seems to me hard to maintain), I would like to ask my current workflow its current state and then navigate to the corresponding page.

How can I get a reference to the instance of the workflow I started an is currently running

I tried the following (which doesn't work, CurrentStateId remains null as mentioned earlier in this forum, however the solution doesn't seem to work for a web app, since the StateMachineTracking service has to be assigned before starting the workflow runtime, which is started by the host):

WorkflowRuntime workflowRuntime = WorkflowRequestContext.Current.WorkflowRuntime;
WorkflowInstance instance = workflowRuntime.GetWorkflow((Guid)Session["WorkflowInstanceId"]);
IRootActivity rootAct = instance.GetWorkflowDefinition();
string currentState = ((AanvraagWorkflow)rootAct).CurrentStateId;

I think GetWorkflowDefinition is not the right call, but how can I read the current state

Thanks in advance,
Ronald



Answer this question

Retrieving current state

  • DanielMac

    I posted an example on doing such a thing here.

    Ariel Schapiro.

  • Ed1112ward

    Ronald, you can "ask" the workflow the next page by making some synchronous call.
    Israel Hilero made a sample of this and its available here. (Its the "Help Desk Support - Windows Forms & ASP.NET Web Forms Applications").
    He made some custom activities that are responsible of transmitting data synchronously to and from the workflow.
    If you take a look a yesterday webcast (slides here) you can see that there is something called "PageFlow" which is being developed by the Asp.Net 2.0 team right now and is the architecture to make workflows controll web navigation.

    Ariel Schapiro.

  • Malic Huang

    Hello Ariel,

    Thanks for your post. However I already studied your example (and did find it very informative). The thing is, your page flow is implemented in the web  application and has to know about the workflows next state (show state) to present the corresponding page (show.aspx).

    Instead, I would like to ask my workflow its current state, and then redirect to the corresponding page. So if the workflow answers: "my current state is Show", then I redirect to show.aspx. This way, when changing the workflow, I do not have to change the page flow manually.

    Kind regards,
    Ronald

  • Gabrielle Erlingen

    Hello,

    As You already now, CurrentStateId is always null (in Beta 1). As suggested by weehyong in post "CurrentStateId is always null", You can use Invoke Method activity to get current state of workflow. I try to do it as decribed in weehyong post and it works for me.

    With regards,
    nrasinec

  • Retrieving current state