loading workflow from xoml file

i save workflow in xoml file now when i load it back its loads fine but i had to cast it into prope type can any body give me better way of doing it .....

XmlReader xmlReader = XmlReader.Create("seq.xoml");

WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

seq.Workflow1 wf1 = (seq.Workflow1)serializer.Deserialize(xmlReader);

WorkflowInstance wfInstance = wfRuntime.CreateWorkflow(xmlReader);

wfInstance.Start();

I mean simply using Activity type for wf1 not works ....




Answer this question

loading workflow from xoml file

  • cx409

    If you are trying to deserialize a workflow from a XOML file you do the following:

    XmlReader xmlReader = XmlReader.Create(@"..\..\Workflow2.xoml");

    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

    Activity wf1 = serializer.Deserialize(xmlReader) as Activity;

    If you want to run a workflow using the XOML file and an XmlReader you do the following:

    XmlReader xmlReader = XmlReader.Create(@"..\..\Workflow2.xoml");

    WorkflowInstance wfInstance = workflowRuntime.CreateWorkflow(xmlReader);

    wfInstance.Start();

    You should not interleave the operations.

  • MarcoL

    Yes, you do not need to have a compiled assembly to run a workflow.   You are able to directly run a workflow using an xml reader that has read the serialized workflow.   It must be a xoml file and there can not be any code beside involve.   If you need something in code beside you need to build that into an assembly and reference it using the TypeProvider.   You are not able to use the xoml.cs file like you would with a compiled type.   If you use VS to create the xoml file you need to remove the x:Class attribute to be able to use activation.   If you need samples for this let me know.



  • lchristensen

    Check the Errors property on the exception that you are getting, like the following:< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

     

    XmlReader reader = XmlReader.Create(path);

    WorkflowInstance instance = null;

    try

    {

        instance = workflowRuntime.CreateWorkflow(reader);

    }

    catch (WorkflowValidationFailedException exp)

    {

        StringBuilder errors = new StringBuilder();

        foreach (ValidationError error in exp.Errors)

        {

            errors.AppendLine(error.ToString());

        }

        MessageBox.Show(errors.ToString(), "Validation errors");

    }

     

    My quess is that you are receiving the following error which you can resolve by removing the x:Class attribute from the xoml file.

     

    error 1564: 'x:Class' cannot be used when the markup is executed directly without creating a new activity type.



  • xlthim

    Hmm so simply put if i chose all xoml from start (by creating workflow project not using code seprated project type ) . Ya only one thing as I am very cozy with this sperated model specailly when handling events I just gona take bit of time . Any ways please provide the samples they gona be of great help. Thanks alot for your timley reply.



  • Paul Farrell

    Ahan ,so this means i dont have to know the concreate type of

    workflow when i desealize it like a sequence workflow with a custom type SQQ1 will be desearlize using

    XmlReader xmlReader = XmlReader.Create(@"..\..\Workflow2.xoml");

    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

    Activity wf1 = serializer.Deserialize(xmlReader) as Activity;

    hmmm moreover can u please verify that by looking this its evident that

    i dont need assembly of workflow

    one more thing is there any way i create a workflow in vs.net 2005 and

    then save it aas a single unit xoml + (code cs or vb.net ) i mean

    can i esacpe form .dll and just save xoml and later desearlize it from xoml .....



  • Mumshelp


    hi when i use following line of code to start workflow it give me runtime error
    "Validation Failed "

    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

    WorkflowInstance wfInstance = wfRuntime.CreateWorkflow(xmlReader);

    wfInstance.Start();


    but the workflow sarts successfully when i modify code a bit

    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

    Activity wf1 = serializer.Deserialize(xmlReader) as Activity;
    WorkflowInstance wfInstance = wfRuntime.CreateWorkflow(wf1.GetType());

    wfInstance.Start();



  • Soaring Skies

    First, create a new file named ActivationSample.xoml and add the following to the file:

    <SequentialWorkflowActivity x:Name="ActivationSample" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow">

    <DelayActivity TimeoutDuration="00:00:05" x:Name="delayActivity1" />

    </SequentialWorkflowActivity>

    Now create an new Sequential Workflow Console Application and update the code in the Program.cs file to the following:

    #region Using directives

    using System;

    using System.Threading;

    using System.Workflow.Runtime;

    using System.Xml;

    #endregion

    namespace WorkflowConsoleApplication1

    {

    class Program

    {

    static void Main(string[] args)

    {

    WorkflowRuntime workflowRuntime = new WorkflowRuntime();

    AutoResetEvent waitHandle = new AutoResetEvent(false);

    workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)

    {

    waitHandle.Set();

    };

    workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)

    {

    Console.WriteLine(e.Exception.Message);

    waitHandle.Set();

    };

    WorkflowInstance instance = workflowRuntime.CreateWorkflow(XmlReader.Create(@"..\..\ActivationSample.xoml"));

    instance.Start();

    waitHandle.WaitOne();

    }

    }

    }

    Make sure you update the path passed to XmlReader.Create to the first file you created.



  • loading workflow from xoml file