在 4.0 中构建一个可创建多个不同工作流并与其通信的 WCF 服务
我是工作流 4.0 和 WCF 的新手,正在努力创建一个 WCF 服务来创建、运行不同类型的工作流并与之通信。
使用工作流 3.5,我能够创建一个很好的 Web 服务,它可以创建和销毁不同类型的工作流,并允许单个界面与不同类型的工作流进行交互。例如,在3.5中创建给定代码的工作流:(其中代码对应工作流类型)
[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);
}
}
然后与any类型的工作流进行通信:
..
WorkflowInstance instance = runtime.GetWorkflow(new Guid(Id));
PassDataEventArgs eve = new PassDataEventArgs(instance.InstanceId, data);
InputData(null, eve);
..
是否可以呈现这样的接口使用 WCF 和工作流 4.0 ?我已经设法使用 WCF 创建不同类型的工作流,但为了与它们进行通信,我不确定如何传递数据。理想情况下,在我的 WCF 服务上调用 passData(Guid id, Object data) 之类的方法会将此数据传递到任何类型的工作流实例(如果工作流当时未处于接收数据的正确状态,则会捕获错误) )。任何人都可以给我任何关于如何在单个 WCF 服务内跨多个工作流类型实现此类通用通信的见解吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 WF4 中,将工作流作为服务运行的常用方法是使用 WorkflowServiceHost。然而,这仅限于每个 WorkflowServiceHost 的单个工作流定义。如果您想要多个工作流程,您可以使用多个 WorkflowServiceHost。
现在,您可以创建一个通用服务,该服务将接受所有消息、检查它们并根据某些条件将它们传递到正确的 WorkflowServiceHost。另一种方法是不使用 WorkflowServiceHost,而是使用 WorkflowApplication,但这意味着需要编写大量管道代码。
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.