Viewing Persisted Workflow State
A few weeks ago at work I was toying around with implementing a viewer for persisted workflow instances (with WF 3.5). While there is a Microsoft sample (Workflow Monitor) that displays tracking information recorded for a workflow instance accompanied by a visual designer, there is no API or tool to view the state of a persisted workflow—the property values and object references that are serialized to the workflow persistence store.
It’s always possible to write a custom persistence service that will serialize workflows in any way you deem fit, but I decided to do something simpler. I wrote a trivial serialization framework that hardly does anything but:
- Query public properties and traverse references recursively;
- Handle cyclic references by storing a set of visited objects;
- Serializing primitive types using their simple string representation.
The result of this serialization is an XML document. Next, I wrote a custom persistence service that derives from SqlWorkflowPersistenceService and invokes my serialization framework in its implementation of SaveWorkflowInstanceState. The serialization result is stored in a versioned table, providing the advantage of querying multiple versions of the same workflow instance.
Here’s the really simple viewer:
Although this is just a proof-of-concept, it shows that it’s very much possible to view persisted workflow information without implementing a full-blown custom persistence service. It’s easy to envision how the serialization can be turned on or off completely, or how it can be optimized to improve performance (binary form, compression, etc.).
If you care to see how it’s done, you can download the whole thing as a Visual Studio solution. Note that you will need to create an appropriate persistence database with a custom table called PersistedWorkflowState (see the LINQ to SQL data context).