The Problem SolverWIndows Workflow Foundation
HomeShow ChangesEditPrintRecent ChangesSubscriptionsLost and FoundFind ReferencesRename



8-4-2008 17:31:228-4-2008 17:31:11

List all versions

Workflow Markup Serializer

Sometimes you just want to be able to create a workflow in code bus save it as a XOML workflow so the end user has the opportunity to modify it.

Well it turns out to be quite easy as the WorkflowMarkupSerializer class is your friend. The following code does just that. And most of the code is to create the workflow in the first place as the serialization part is just 3 lines!

using (XmlWriter writer = XmlWriter.Create("MyWorkflow.xoml"))
    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
    SequentialWorkflowActivity myWorkflow = new SequentialWorkflowActivity();

    ListenActivity listen = new ListenActivity();
    EventDrivenActivity leftBranch = new EventDrivenActivity();
    leftBranch.Activities.Add(new DelayActivity("LeftDelay")
        TimeoutDuration = TimeSpan.FromSeconds(5)

    EventDrivenActivity rightBranch = new EventDrivenActivity();
    rightBranch.Activities.Add(new DelayActivity("RightDelay")
        TimeoutDuration = TimeSpan.FromSeconds(5)

    serializer.Serialize(writer, myWorkflow);

This produces the following XOML workflow:

<?xml version="1.0" encoding="utf-8"?>
<SequentialWorkflowActivity x:Name="SequentialWorkflowActivity"
  <ListenActivity x:Name="listenActivity1">
    <EventDrivenActivity x:Name="eventDrivenActivity1">
      <DelayActivity TimeoutDuration="00:00:05" x:Name="LeftDelay" />
    <EventDrivenActivity x:Name="eventDrivenActivity2">
      <DelayActivity TimeoutDuration="00:00:05" x:Name="RightDelay" />
Wiki Usage

This wiki site is supposed to be a shared resource. As a shared resource everyone is encouraged to add new content or modify existing content!

Enjoy the WF wiki.

Recent Topics