使用 WorkflowServiceHost 托管工作流

发布于 2024-09-01 19:51:48 字数 1209 浏览 3 评论 0原文

好的,所以我可能会错误地处理这个问题,但本质上我正在尝试使用 4.0 中的新 WF 服务来构建托管 WF 服务的 Windows 服务。目前我已经构建了客户端(包含一个简单的 Activity XAML)和服务(在 XAMLX 文件中实现的 WF 服务)项目。

我对每一个都尝试过简单的“hello worlds”。客户端已托管在 WorkflowApplication 中,我最初将该服务设置为默认 WF 服务项目模板。两者似乎都很好。

由于我想在没有 IIS 的情况下托管服务,因此我的下一次尝试自然是在 WorkflowServiceHost 中托管我的服务。为此,我可以使用 XamlServices.Load() 并将其返回的对象以及端点的 URI 传递给 WorkflowServiceHost 构造函数。我很担心,因为没有像 WorkflowApplication 类中那样的 Run() 成员方法。我假设 Open() 方法会将服务主机对象作为服务打开,并且它将启动工作流的实例,但没有任何指示。

起初,我将服务工作流程设置为在启动时简单地写入文本文件,但什么也没发生。我尝试使用断点进行调试,但由于它在运行时加载 XAMLX 文件,因此 VS 不允许我调试 WF。因此,我尝试稍微更改客户端项目以使用 WorkflowServiceHost 而不是 WorkflowApplication。我使用了与测试 hello world 样式工作流程相同的工作流程,这次没有输出到控制台,并且 WorkflowApplication 之前的工作流程成功了。

以下是我对客户端所做的在控制台项目中托管工作流服务的基础知识。如果有人想查看工作流程的 XAML,请告诉我,我将更新此问题。这是 Main() 中的托管代码。

const String clientAddress = "http://localhost:9998/Client";    
WorkflowServiceHost wfHost = new WorkflowServiceHost( new ClientWf(), new Uri(clientAddress) );
wfHost.Open();

while( Console.ReadKey().KeyChar.ToString().ToUpper() != "X" ) {    }

wfHost.Close();

Ok, so I may be approaching this incorrectly but essentially I'm trying to play with new WF services in 4.0 to build up to a Windows service that hosts a WF service. At the moment I have constructed client (containing a simple Activity XAML) and service (WF service implemented in a XAMLX file) projects.

I have tried simple "hello worlds" for each one. The client has been hosted in a WorkflowApplication and I initially setup the service as the default WF service project template. Both seem to be fine there.

Since I want to host a service without IIS, naturally my next attempt was to host my service in a WorkflowServiceHost. Doing this I can use XamlServices.Load() and pass the object it returns to the WorkflowServiceHost constructor along with a URI for the endpoint. I was concerned because that there is no Run() member method like there is in the WorkflowApplication class. I assumed that the Open() method would open the service host object as a service and that it would start an instance of the workflow but there is no indication of it.

At first I setup the service workflow to simply write to a text file when it started but nothing happened. I tried to debug with breakpoints but since it is loading a XAMLX file at runtime, VS doesn't allow me to debug the WF. So I tried altering the client project a bit to use a WorkflowServiceHost instead of a WorkflowApplication. I used the same workflow used to test out the hello world style workflow and this time there was no output to console and the WorkflowApplication was successful with that previously.

Here's the very basics of what I did with the client to host the workflow service in the console project. If anyone wants to see the XAML for the workflow let me know and I'll update this question. Here's the hosting code in Main().

const String clientAddress = "http://localhost:9998/Client";    
WorkflowServiceHost wfHost = new WorkflowServiceHost( new ClientWf(), new Uri(clientAddress) );
wfHost.Open();

while( Console.ReadKey().KeyChar.ToString().ToUpper() != "X" ) {    }

wfHost.Close();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路还长,别太狂 2024-09-08 19:51:48

我发现,由于您无法直接启动由 WorkflowServiceHost 对象包装的 WF 实例,因此运行它有点痛苦,并且通过像您这样的简单方法调用几乎不可能使用 WorkflowApplication 完成。有一个“技巧”可以让 WF 开火,但需要一些技巧,但目前我还没有时间进行。 MSDN 有一个关于在这种情况下可以执行的操作的模糊参考 此处,在托管非服务工作流程下。

这是我采用的解决方案:同时使用 WorkflowServiceHost 和 WorkflowApplication。你为什么问?嗯,因为我试图在一个小小的包中完成所有的事情。我还将其构建为我工作的自定义服务模型,最好将业务逻辑 (WorkflowApplication) 与所有通信实现 (WorkflowServiceHost) 分开。该服务以这种方式启动得很好,因为当然现在是我的底层通信。工作流从接收活动开始,WorkflowSericeHosts 在关联工作流的根部查找某种类型的消息传递活动,以便启动实例。

现在我是一名快乐的露营者。我的业务逻辑按照预期完成了它应该做的事情,并且工作流服务正在很好地充实。更好的是,我有一个模型,可以动态地插入业务逻辑来动态设置和部署自定义数据处理/处理服务。现在只是为了完美回调以更新远程“仪表板”,这就是我接下来要做的。

What I found out is that since you cannot directly start the WF instance that is wrapped by the WorkflowServiceHost object, its a bit of a pain to run it and pretty much impossible by a simple method call like you can accomplish with a WorkflowApplication. There is a "trick" to have the WF fire but takes a bit of a hacking that I haven't given time to at this juncture. MSDN has an obscure reference of what you can do in this scenario here, under Hosting Non-Service Workflows.

This is the solution that I went with: using both the WorkflowServiceHost AND the WorkflowApplication. Why you ask? Well because I was trying to do a whole lot of everything in one tiny little package. I'm also building this as a custom service model for my work and it's better that I separate the business logic (WorkflowApplication) from all of the communication implementation (WorkflowServiceHost). The service fires just fine this way because of course now my underlying comm. workflow starts with a receive activity and WorkflowSericeHosts look for some type of messaging activity at the root of the associated workflow in order to start an instance.

Now I'm a happy camper. My business logic does what it's supposed to do as expected and the workflow service is fleshing out nicely. What's even better is that I have a model where I can dynamically drop in business logic to setup and deploy custom data processing/crunching services dynamically. Now just to perfect call backs to up date a remote "dashboard", that's what I'm moving on to next.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文