I have not been able to find any information about two CreateWorkflow overloads in the WorkflowRuntime class:
CreateWorkflow(XmlReader workflowDefinitionReader, XmlReader rulesReader, Dictionary<string, object> namedArgumentValues) and
CreateWorkflow(XmlReader workflowDefinitionReader, XmlReader rulesReader, Dictionary<string, object> namedArgumentValues, System.Guid instanceId)
I have two questions:
1. Given that there are issues with argument passing and Xaml-only (or "no code") defintions, do these methods have any purpose
2. If yes, can you provide some information about the "rulesReader" argument
thanks

WorkflowRuntime.CreateWorkflow overloads
Paul Ballard
Matt - this works fine:
<SequentialWorkflowActivity x:Class="HelloWorld.HelloWorldWorkflow" x:Name="HelloWorldWorkflow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<CodeActivity x:Name="CodeActivity1" ExecuteCode="CodeActivity1_ExecuteCode"/>
<x:Code>
<![CDATA[
void CodeActivity1_ExecuteCode(object o,EventArgs e)
{
System.Console.WriteLine("Hello World");
}
public string Prop
{
get{return _Prop;}
set{_Prop=value;}
}
string _Prop;
]]>
</x:Code>
</SequentialWorkflowActivity>
John Ericson
My apologies for not being more clear in the original posting. I believe Matt hit the nail on the head regarding my first question. See http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=231780&SiteID=1 for some additional background. We have a lot of interest in providing workflow design capability to business users but the requirements of creating a mechanism to generate code and then find a way to compile and store it in our application are significant obstacles.
I do appreciate the prompt feedback and thank (several of) you for clarifying the use "rulesReader" argument.
tom
WizDum
So what I need is this:
namespace
MyXoml{
public class MySequentialActivity : SequentialWorkflowActivity{
private string _prop; protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext){
Console.WriteLine("Property set was {0}", Prop); return base.Execute(executionContext);}
public string Prop{
get { return _prop; } set { _prop = value; }}
}
}
and this Xoml:
<
myact:MySequentialActivity x:Name="HelloWorldWorkflow" xmlns:myact="clr-namespace:MyXoml;Assembly=WorkflowConsoleApplication20,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"></
myact:MySequentialActivity>With this in the host:
Dictionary<string, object> wfargs = new Dictionary<string, object>();wfargs.Add(
"Prop", "Setting property");instance = workflowRuntime.CreateWorkflow(
XmlReader.Create(@"..\..\helloworld.xoml"), null, wfargs);Lixin D
If loading rules xml file with xoml workflow is supported in WWF Beta 2, can you provide and examples where CreateWorkflows and Start will not throw an error. Any info would be appreciated.
Can you load a rules file with xoml file and parameters collection when calling CreateWorkflow. There seems to be an overloaded definition for CreateWorkflow, but I cannot get it to work. Any examples of loading rules, xoml, and parameters without having to recompile would be appreciated. I just want to CreateWorkflow and Start a workflow.
If anyone has working examples, please reply ASAP.
Thanks in advance,
John Portnov
Jing Sun
Tom,
Can you load a rules file with xoml file and parameters collection when calling CreateWorkflow. There seems to be an overloaded definition for CreateWorkflow, but I cannot get it to work. Any examples of loading rules, xoml, and parameters without having to recompile would be appreciated. I just want to CreateWorkflow and Start a workflow.
If anyone has working examples, please reply ASAP.
Thanks in advance,
John Portnov
Tomast
Tom,
Thanks for the examples for Beta 2. Although the example you posted at
http://blogs.msdn.com/tomlake/archive/category/13216.aspx
works, it does not solve my problem. I need to raise events with a state workflow. The example you posted has 2 states and no external events are being raised. When I use a State with an event which references a typelibrary, I am not able to execute the CreateWorkflow line of code (Validation error for InterfaceType). Below is the xoml syntax that works, and the xoml syntax that does not work. Any feedback would be appreciated.
This works
----------
<ns0:BaseWorkflow PurchaseOrder="{p1:Null}" InitialStateName="InitialState" x:Name="Workflow1" DynamicUpdateCondition="{x:Null}" CompletedStateName="CompletedState" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:ns1="clr-namespace:ADPSendEmail;Assembly=ADPSendEmail, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:p1="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:BaseStateMachineLibrary;Assembly=BaseStateMachineLibrary, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<StateActivity x:Name="InitialState">
<StateInitializationActivity x:Name="EmailCreatedEvent">
<CodeActivity x:Name="codeActivity1" ExecuteCode="{ActivityBind Workflow1,Path=codeActivity_ExecuteCode}" />
<CodeActivity x:Name="CreateEmailRequest" ExecuteCode="{ActivityBind Workflow1,Path=CreateEmailRequest_ExecuteCode}" />
<ns1:ADPWSSendEmail toA="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_toA1}" x:Name="EmailCreatedSendEmailActivity" subj="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_subjA1}" name="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_nameA1}" Description="Send Manager email notification" body="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_bodyA1}" fromA="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_fromA1}" xfilepath="{x:Null}" />
<IfElseActivity x:Name="isOver5000">
<IfElseBranchActivity x:Name="greaterThan5000">
<IfElseBranchActivity.Condition>
<RuleConditionReference ConditionName="Condition1" />
</IfElseBranchActivity.Condition>
<CodeActivity x:Name="greaterThan" ExecuteCode="{ActivityBind Workflow1,Path=Greater}" />
</IfElseBranchActivity>
<IfElseBranchActivity x:Name="lessThan5000">
<CodeActivity x:Name="lessThan" ExecuteCode="{ActivityBind Workflow1,Path=Less}" />
</IfElseBranchActivity>
</IfElseActivity>
<SetStateActivity x:Name="setApprovalState" TargetStateName="CompletedState" />
</StateInitializationActivity>
</StateActivity>
<StateActivity x:Name="CompletedState" />
</ns0:BaseWorkflow>
-------------
This does not work (the xoml generating the problem is in bold)
----------------------------------------------------------------
<ns0:BaseWorkflow PurchaseOrder="{p1:Null}" InitialStateName="InitialState" x:Name="Workflow1" DynamicUpdateCondition="{x:Null}" CompletedStateName="CompletedState" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:ns1="clr-namespace:ADPSendEmail;Assembly=ADPSendEmail, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:p1="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-namespace:BaseStateMachineLibrary;Assembly=BaseStateMachineLibrary, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<StateActivity x:Name="InitialState">
<StateInitializationActivity x:Name="EmailCreatedEvent">
<CodeActivity x:Name="codeActivity1" ExecuteCode="{ActivityBind Workflow1,Path=codeActivity_ExecuteCode}" />
<CodeActivity x:Name="CreateEmailRequest" ExecuteCode="{ActivityBind Workflow1,Path=CreateEmailRequest_ExecuteCode}" />
<ns1:ADPWSSendEmail toA="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_toA1}" x:Name="EmailCreatedSendEmailActivity" subj="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_subjA1}" name="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_nameA1}" Description="Send Manager email notification" body="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_bodyA1}" fromA="{ActivityBind Workflow1,Path=EmailCreatedSendEmailActivity_fromA1}" xfilepath="{x:Null}" />
<IfElseActivity x:Name="isOver5000">
<IfElseBranchActivity x:Name="greaterThan5000">
<IfElseBranchActivity.Condition>
<RuleConditionReference ConditionName="Condition1" />
</IfElseBranchActivity.Condition>
<CodeActivity x:Name="greaterThan" ExecuteCode="{ActivityBind Workflow1,Path=Greater}" />
</IfElseBranchActivity>
<IfElseBranchActivity x:Name="lessThan5000">
<CodeActivity x:Name="lessThan" ExecuteCode="{ActivityBind Workflow1,Path=Less}" />
</IfElseBranchActivity>
</IfElseActivity>
<SetStateActivity x:Name="setApprovalState" TargetStateName="EmailApprovalState" />
</StateInitializationActivity>
</StateActivity>
<StateActivity x:Name="EmailApprovalState">
<EventDrivenActivity x:Name="EmailApprovedEvent">
<HandleExternalEventActivity Invoked="EmailApproved_Invoked" x:Name="EmailApprovedHandleExternalActivity" EventName="EmailApproved" InterfaceType="{x:Type iServeLocalServices.iServeInterface}">
<HandleExternalEventActivity.ParameterBindings>
<WorkflowParameterBinding ParameterName="e">
<WorkflowParameterBinding.Value>
<ActivityBind Name="Workflow1" Path="OrderEvtArgs" />
</WorkflowParameterBinding.Value>
</WorkflowParameterBinding>
<WorkflowParameterBinding ParameterName="sender">
<WorkflowParameterBinding.Value>
<ActivityBind Name="Workflow1" Path="OrderSender" />
</WorkflowParameterBinding.Value>
</WorkflowParameterBinding>
</HandleExternalEventActivity.ParameterBindings>
</HandleExternalEventActivity>
<ns1:ADPWSSendEmail toA="{ActivityBind Workflow1,Path=EmailApprovedSendEmailActivity_toA1}" x:Name="EmailApprovedSendEmailActivity" subj="{ActivityBind Workflow1,Path=EmailApprovedSendEmailActivity_subj1}" name="{ActivityBind Workflow1,Path=EmailApprovedSendEmailActivity_name1}" Description="Send approved email" body="{ActivityBind Workflow1,Path=EmailApprovedSendEmailActivity_body1}" fromA="{ActivityBind Workflow1,Path=EmailApprovedSendEmailActivity_fromA1}" xfilepath="{ActivityBind Workflow1,Path=EmailApprovedSendEmailActivity_xfilepath1}" />
<SetStateActivity x:Name="EmailApprovedSetStateActivity" TargetStateName="CompletedState" />
</EventDrivenActivity>
</StateActivity>
<StateActivity x:Name="CompletedState" />
</ns0:BaseWorkflow>
------------------------------------------------------------------
Can you provide an example (with Beta 2) with three states where you raise event(s) in a state workflow
Sincerely,
John Portnov
Hi_GC
Use the following template for your Program.cs file for Xoml activation. Just update the path to your xoml and rules file, add any referenced assemblies you need to the TypeProvider and add the parameters.
#region Using directives
using System;
using System.Threading;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.Runtime;
using System.Xml;
using System.IO;
using System.Collections.Generic;
#endregion
namespace WorkflowConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
AutoResetEvent waitHandle = new AutoResetEvent(false);
workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
{
Console.WriteLine("Workflow completed.");
waitHandle.Set();
};
workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
{
Console.WriteLine(e.Exception.Message);
waitHandle.Set();
};
string workflowFilename = @"..\..\Workflow1.xoml";
string rulesFileName = @"..\..\Workflow1.xoml.rules";
// Add referenced assemblies to the TypeProvider
// TypeProvider typeProvider = new TypeProvider(workflowRuntime);
// workflowRuntime.AddService(typeProvider);
// Creating workflow from XAML file
WorkflowInstance workflowInstance;
using (XmlReader workflowReader = XmlReader.Create(workflowFilename))
{
XmlReader rulesReader = null;
if (File.Exists(rulesFileName))
{
rulesReader = XmlReader.Create(rulesFileName);
}
Dictionary<string, object> parameters = new Dictionary<string, object>();
workflowInstance = workflowRuntime.CreateWorkflow(workflowReader, rulesReader, parameters);
}
// Start workflow
workflowInstance.Start();
waitHandle.WaitOne();
}
}
}
Erik Edlund
I'm not sure if this was the intent of #1 from the original poster, but I believe you or another MS rep indicated that you would not be able to define parameters/properties (at least through the designer) for XAML based workflows. This means that passing in parameters to the workflow becomes difficult if not impossible. THis also means that XAML-only workflows become much less appealing, at least in my mind because they cannot take parameters. My understanding is that the alternative is to create a local service and have every XAML-only workflow start with an event if it needs parameters.
Or, is there just confusion about being able to define parameters on a XAML-only workflow Can I do it directly in the XAML and have the designer leave it alone
Matt
BringerOD
Dania151638
FreddyFresh
Hi,
I'm not quite sure what you mean when you say "there are issues with argument passing."
These XmlReader overloads allow you to pass your workflow in as Xaml with no prior compilation required (declarative workflows). The rulesReader argument allows you to pass a declarative rules file that contains all of the rule definitions use by your workflow. This allows you to both have a declarative workflow AND make decisions within it via our rules OM with no code. Please see our samples/labs for more information on declarative rules.
Although Beta2 does have a couple of known issues around the execution of Xaml-only workflows, this is a fully supported feature for RTM and we are actively working on resolving all of these issues.
Thanks!
Big Ben
Can you load a rules file with xoml file and parameters collection when calling CreateWorkflow. There seems to be an overloaded definition for CreateWorkflow, but I cannot get it to work. Any examples of loading rules, xoml, and parameters without having to recompile would be appreciated. I just want to CreateWorkflow and Start a workflow.
If anyone has working examples, please reply ASAP.
Thanks in advance,
John Portnov
Very Anonymous
I am not sure what you are referring to in terms of #1.
But - I believe these overloads do have usage. The rulesReader is an XmlReader for the .rules file if you have Rules you'd like to have the workflow run.
genyded