Using the persistence service in a WCF 3.5 hosted workflow


Using the persistence service in a WCF 3.5 hosted workflow   


By Serge Luca

MVP Windows Workflow Foundation

This morning a  colleague at U2U asked me how to use the persistence service in a workflow hosted in WCF (.Net 3.5 and Visual Studio 2008).

I’ve created  a quick (and dirty, sorry) step by step tutorial on how to achieve it.

Click here to download the code.

1.Start Visual Studio 2008 and create a new Sequential Workflow Service Library project ; call it WFServiceLibrary.


A workflow with a WF-WCF 3.5 Receive activity linked to the GetData method of a IWorkflow interface will be generated:





2.Drag and drop a code activity into the Receive activity and set the ReturnValue to a funny string



3.Create a WCF host for the workflow by generating a Console project


…and add the following references:



And don’t forget to add a reference to the WFServiceLibrary as well…

4.In the Host project, the workflow and don’t forget to create the persistence database with the scripts provided with the .Net framework :


The second parameter of the persistence service (unloadOnIdle) is set to true, which means the workflow will be persisted by the workflow runtime when it is idle; add a delay activity after the Receive activity to make it idle:


Set its timeout duration to 30 secs.

5.Let’s create the client application by adding a Console application to the solution:


Don’t forget to reference the following .Net assemblies and the library project (just to get the interface definition: I told you it was quick and dirty)


Implement the client-side code in the Main() function :


6.Start the Host (if your run it Vista, I strongly suggest that you start it with admin privileges):


7.Start the client:


Ok, the communication works…

8.Check the persistence database (InstanceState table):


yes the workflow is persisted!!! After 30 seconds, it will be removed from the database.

Click here to download the code.

This hands-on training is the property of U2U and may not be organized in class or in group without the prior written permission of U2U. Should you wish to organize this hands-on training in your company or institution, please contact U2U first to enter into a licence agreement. Each trainer or teacher using this hands-on training should have a licence agreement. Please ask your trainer or U2U whether he or she has entered into a licence agreement with U2U.

The hyperlink "" to this hands-on training may be placed on your website for free, on the condition that the name and the logo of U2U are clearly mentioned in the reference. Please send us a mail containing the link to the web page our reference is used on.


One response to “Using the persistence service in a WCF 3.5 hosted workflow

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s