Share via


Viewing a Workflow's Definition in Xoml

I attended a "get to know your son's/daughter's teacher" event last night for my son's new school (new in that it is still under construction). A major theme I took away is that teaching styles have drastically changed in the little bit of time I've been out of school (ok, maybe not little but it hasn't been looong). One thing I constantly heard was the goal of getting the students to think logically and derive their own conclusions. In order to keep the thinking on track, the teacher occasionally throws out little bits of information to get different gears in their heads rolling. Where is this going? This post is meant to throw a little curveball to get you thinking down another avenue of Windows Workflow Foundation that you might haven't seen yet.

When you create a new workflow project using the New Project Wizard you receive a nice project template consisting of a designer generated source file and a code behind file that you use whenever your workflow needs some additional logic (e.g. the CodeActivity needs a method for its ExecuteCode property). Did you know that your designer generated code can also be in the form of a Xml file? This Xml file is known as a xoml file. If you want to see what one of these looks like, right click on your project in Solution Explorer, select Add, New Item and select any item template that mentions something about "with code seperation", e.g. Sequential Workflow (with code seperation). What you get is a workflow definition expressed in xoml.

So now you're saying "oh man, that is cool. But I have this workflow I've been working on that I know would be painful to convert". Let's run a little experiment then, ok.

In the code that starts the WorkflowRuntime, adds any necessary services and then kicks off your workflow (i.e. in your workflow hosting code), let's add just a few lines. Follow these steps:

  1. Add 2 using statements for System.Workflow.ComponentModel.Serialization and for System.IO
  2. Add the following code after the call to StartWorkflow (I suggest you add it right after that call otherwise your workflow may finish before you get a chance to serialize it)

WorkflowMarkupSerializer ser = new WorkflowMarkupSerializer();

TextWriter tw = new StreamWriter(@"C:\myWorkflow.xoml");

ser.Serialize(workflowInstance.GetWorkflowDefinition(), tw);

tw.Close();

Once you run your workflow, take a look at the myWorkflow.xoml file and voila! Now you'll have to do a little massaging on this file if you actually wanted to go ahead and create a new workflow project with it (tip: create a new sequential workflow with code seperation and follow what it does). Have fun exploring this awesome new technology and as always, don't hestitate to contact me.

Comments

  • Anonymous
    September 28, 2005
    Cool stuff! Where can I find XOML specs, anonated XSD, etc?
  • Anonymous
    October 22, 2005
    There really are a lot of shortcomings in the WWF beta 1 of XOML. A key omission is that lack of support for storing the workflow layout ...which is absolutely key for business analysts ...and especially for the state machine workflow.

    Michael Herman
    Parallelspace Corporation
  • Anonymous
    April 25, 2006
    I downloaded WFPad (Beta 2). It is really cool. It reminds me of Lab 10 (WWF using DesignerControl). I really like that you can apply XAML/XOML changes visually directly to the Workflow. I have a few questions for you.Is it possible to talk to you on the phone?Sincerely,John Portnov
  • Anonymous
    November 13, 2006
    The comment has been removed
  • Anonymous
    June 09, 2009
    PingBack from http://quickdietsite.info/story.php?id=1717