Ok, this is my follow-up post to .Net Framework Profiles, where I very naïvely though I persistence in WF4 was all about using the correct target framework. As it turned out, they changed the persistence model between beta 1 and beta 2, and the tutorial was apparently written for beta 1.
So here’s my changes to the Microsoft tutorial How to: Create and Run a Long Running Workflow in order to make it work for Windows Workflow Foundation 4 beta 2.
First of all, since they have replaced the SqlPersistanceProvider with SqlWorkflowInstanceStore, you have to generate a different persistence database. Instead of the scripts mentioned in the tutorial, you should use SqlWorkflowInstanceStoreSchema.sql and SqlWorkflowInstanceStoreLogic.sql to generate your database. They are still found in C:\Windows\Microsoft.NET\Framework<current version>\sql\en.
Add the correct references. Disregard the references mentioned in the tutorial. Instead add references to System.Runtime and System.Activities.DurableInstancing. These are both included in the Client Profile, rendering my previous post completely obsolete (and it was only a couple of hours old).
Yep, you should still add a connection string to your persistence database.
Add a using statement for System.Activities.DurableInstancing instead of System.ServiceModel.Persistence.
Next, add a SqlWorkflowInstanceStore to the workflow application
wfApp.InstanceStore = new SqlWorkflowInstanceStore(connectionString);
In order to tell the workflow to persist when it goes idle, replace the Idle action with a PersistableIdle action.
//Remove this from the previous step
- Yeah, same, same
- Since the database schema is different, instead of looking in the Instances table, look in the **[System.Activities.DurableInstancing].[InstancesTable] **table (yeah, redundancy is fun, always suffix your tables with table and your databases with database!).
Now, it should work. At least it did for me. But just to be safe, I’ll decorate this post with the official Works On My Machine seal of awesomeness.