Reputation: 1
I'm new to workflow 4.0 and WCF and am struggling to create a WCF service that creates, runs and communicates with Workflows of different types.
Using workflow 3.5 I was able to create a nice webservice that creates and destroys workflows of different types, and allows a single interface to talk to workflows of varying types. For example, to create a workflow of a given code in 3.5: (where a code corresponds to a workflow type)
[WebMethod]
public string CreateWorkflow(int code)
{
WorkflowRuntime runtime = createRuntime();
try
{
Type type = GetWorkflowType(code);
string reply = "";
WorkflowInstance instance =
runtime.CreateWorkflow(type);
instance.Start();
reply = instance.InstanceId.ToString();
instance.Unload();
return reply;
}
catch (Exception e)
{
return e.ToString();
}
finally
{
closeRuntime(runtime);
}
}
And then to communicate to a workflow of any type:
..
WorkflowInstance instance = runtime.GetWorkflow(new Guid(Id));
PassDataEventArgs eve = new PassDataEventArgs(instance.InstanceId, data);
InputData(null, eve);
..
Is it possible to present such an interface using WCF and workflow 4.0 ? I've managed to create workflows of different types using WCF, but to communicate with them i'm not sure how to pass data along. Ideally invoking a method like passData(Guid id, Object data) on my WCF service would pass this data along to the instance of a workflow of any type (catching an error if the workflow is not in the correct state to recieve data at that time). Can anyone please give me any insights as to how I could achieve such generic communications across multiple workflow types inside a single WCF service?
Upvotes: 0
Views: 585
Reputation: 27632
IN WF4 the usual way to run a workflow as a service is to use the WorkflowServiceHost. This is however restricted to a single workflow definition per WorkflowServiceHost. If you want multiple workflows you would use multiple WorkflowServiceHost's.
Now you can create a generic service that would accept all messages, inspect them and based in some criteria pass them on to the correct WorkflowServiceHost. An alternative is not to use the WorkflowServiceHost but use WorkflowApplication instead but that would mean writing a lot of plumbing code.
Upvotes: 1