The serialization of workflows created with Windows Workflow Foundation (WWF) is quite easy. The key to serialize a workflow is to use WorkflowMarkupSerializer class that provides functionalities to serialize and deserialize workflows to XAML. This class is used by the WWF workflow designer control to persist data to its file.
The following example creates an instance of a sequential workflow, adds a delay activity to it and then serializes the workflow instance using the WorkflowMarkupSerializer class. The rest is pretty straightforward.
/// Declares attributes
StringBuilder sbOutput = null;
XmlWriter writerXml = null;
WorkflowMarkupSerializer wkfSerializer = null;
SequentialWorkflowActivity wkfInstance = null;
/// Creates a new sequential workflow
wkfInstance = new SequentialWorkflowActivity();
/// Creates a delay activity
DelayActivity delay = new DelayActivity();
/// Sets timeout to two minutes
delay.TimeoutDuration = new TimeSpan(0, 2, 0);
/// Adds the delay activity to the sequential workflow
/// Creates an instance of the string builder
/// that holds the output content
sbOutput = new StringBuilder();
/// Creates an instance of the XmlTextWriter.
writerXml = XmlTextWriter.Create(sbOutput);
/// Creates an instance of the Workflow Markup Serializer
wkfSerializer = new WorkflowMarkupSerializer();
/// Serializes the workflow instance
/// Sends output content to console.
catch (Exception ex)
/// Releases instances
sbOutput = null;
writerXml = null;
wkfSerializer = null;
if (wkfInstance != null)
wkfInstance = null;