locked
loading workflow from xoml file RRS feed

  • Question

  • 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 ....

    Saturday, April 22, 2006 8:11 PM

Answers

  • 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.

    Monday, April 24, 2006 10:57 PM

All replies

  • 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.
    Sunday, April 23, 2006 5:26 AM
  • 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 .....

    Sunday, April 23, 2006 4:54 PM
  • 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.

    Sunday, April 23, 2006 5:37 PM
  • 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.

     

    Monday, April 24, 2006 5:43 AM
  •  
    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();

    Monday, April 24, 2006 5:48 AM
  • Check the Errors property on the exception that you are getting, like the following:

     

    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.

    Monday, April 24, 2006 10:27 PM
  • 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.

    Monday, April 24, 2006 10:57 PM
  • Hello I need to edit the xoml file and replaces one of the user existing in Workflow with another user. Any idea how to do that?

    Muhammad Ali

    Thursday, December 13, 2012 2:18 PM
  • Hello I need to edit the xoml file and replaces one of the user existing in Workflow with another user. Any idea how to do that?

    Muhammad Ali



    Muhammad Ali

    Thursday, December 13, 2012 2:18 PM