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.

sshot-185

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

sshot-186

sshot-187

sshot-188

 

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

sshot-190

sshot-189

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

sshot-191

…and add the following references:

sshot-192

 

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

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

sshot-193

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:

sshot-194

Set its timeout duration to 30 secs.

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

sshot-195

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)

sshot-201

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

sshot-196

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

sshot-198

7.Start the client:

sshot-199

Ok, the communication works…

8.Check the persistence database (InstanceState table):

sshot-200

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 "www.u2u.be/msdna" 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 comment