views:

34

answers:

1

Is it possible to create workflows dynamically? I need to generate a WF dynamically based on a set of business logic and service execution sequence I get as input to the system. Is it possible for me to generate the workflow.xaml dynamically without using the wf designer and execute in the cloud ?

+2  A: 

Yes - you can create xaml file using simple file I/O routines or XML manipulation libraries but the best bet would be using XamlXmlWriter class.

Once workflow xaml is ready, you can execute it using (as sighted in this article)

WorkflowInstance instance = runtime.CreateWorkflow(
      XmlTextReader.Create("..\\..\\WorkflowInXML.xml"));
instance.Start();

You can also load activities from xaml in WF4 - check this article for the same.

VinayC
Thank you very much. This is very helpful for my work.
Kumaripaba
The code example and the MSDN article is about WF3 and has no relation to workflow 4. The ActivityXamlServices is the way to go in WF4.
Maurice
@Maurice - yes, the article is dated but the method (CreateWorkflow) still exists and relevant - thats why I have quoted it. It must be noted that ActivityXamlServices allows to load only activity tree and not complete workflow.
VinayC