Loading persisted workflow after workflowdefinitio

2019-02-12 18:46发布

问题:

How to solve this problem (in WF4):

I create a workflow in xaml and start several instances of it, I have a persistancestore and all workflows persist on a bookmark half way their workflow.

Now I stop the application

If I restart te application everything is resumed, en nicely completes.

But what if I want to change the workflow definition after the running instances persist? the only way to load the running workflows (that I was able to find) is the following way:

        WorkflowApplication wfapp = new WorkflowApplication(new WorkflowDefinition());
        wfapp.InstanceStore = new SqlWorkflowInstanceStore(connStr);

        wfapp.Load(wfGuid);

So you need the workflow definition, if it has changed during the persistance, things go horribly wrong.

What is the best way to solve this?

回答1:

This scenario is a bit of a problem. There is no way to migrate am older workflow definition to the new format. I have done some limited testing and some scenarios with adding/deleting activities that where not yet executing worked fine. But then I also has scenarios go badly wrong, including re executing an already finished activity.

As far as I am aware there is no good way to solve the problem other than tracking the version of the XAML/assembly used to create the workflow and checking that when you want to restart a workflow to determine the workflow version to use.



回答2:

May be it helps

http://msdn.microsoft.com/en-us/magazine/dd727506.aspx



回答3:

Many versions of the same workflow has to coexist. I mean, the old instances has to finish with the old workflow version, and the new ones has to begining with new workflow version. In my case, we have workflow services. It's on configuration where a router describe the order in which instances try to be executed. If an instance cannot start working with one version, the next one is tried, and so on.

Also, if your change doesn't involve changes in workflow variables, contracts exposed, etc... old and new workflow instance versions can run on the same workflow version. You'll know that, testing it.



回答4:

It's not so much an issue with Windows Workflow as it is the SQL persistence service. You could create your own persistence service that can handle this situation, either by supporting conversion of the old workflow into the new workflow or something more abstract, like a persistence service that serializes as XML/JSON, something that might more easily support deserialization of one version as another version.



回答5:

It is possible to load persisted wf instance after changing the definition in WF4 - you have to parse and change the xml files that the wf engine stores. You should create two equal workflows : with the old version and the new version and to compare them in order to remove the differences. This must be done for the definition xml and the complex data xml that is used to store the workflow state. Parsing it with LinqToXML will save you lots of time and you have to be sure that you have checked all the differences - if there is one difference left, the wf will not be able to Load. There is one element "ResumeData", which you could find in the wf state xml, which is too heavy to parse, but the good news is that you can simply remove it.