带有工作线程的 WCF 服务

编程入门 行业动态 更新时间:2024-10-26 21:30:28
本文介绍了带有工作线程的 WCF 服务 - 如何设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 WCF 服务,它为一些客户提供服务.设计是:

I have a WCF Service that serves some clients. The design is :

WCF 服务层业务逻辑层数据访问层(LINQ-To-Entities)

我需要一个工作线程来对数据库进行一些连续的工作(查找新记录,如果找到的话 - 以推送"方式向客户端发送信息,这意味着 - 客户端将托管一个服务所以它可以从这个工作线程接收推送"通知).

I need to have a worker thread that does some continuous work on the database (looks for new records, and if finds any - sends information to the client in a 'Push' manner, meaning - the client will be hosting a service so it can receive 'push' notifications from this worker thread).

我将在 Windows 服务上托管 WCF 服务.

I will host the WCF service on a windows service.

问题是:在我的设计中,这个工作线程应该放在哪里?它是否应该与 WCF 服务一起在 Windows 服务的Program.cs"的Main()"中生成?(这意味着它应该是 WCF 服务程序集的一部分)或者它应该是业务逻辑层的一部分 - 因此是业务逻辑"程序集的一部分?

Question is : Where do I fit this worker thread in my design ? Should it be spawned in the 'Main()' of the Windows Service's 'Program.cs' along-side the WCF service ? (and this means it should be part of the WCF Service assembly) Or should it be part of the Business Logic layer - and thus part of the 'Business Logic' assembly ?

我的想法:

推荐答案

为什么它需要成为任一程序集的一部分?我会将这个工作线程完全托管在它自己的进程中.例如,将其托管在单独的 Windows 服务中.

Why does it need to be part of either assembly? I would host this worker thread in it's own process entirely. Host it in a separate windows service for example.

然后它可以轮询数据库并将数据推送到客户端.

It can then poll the database and push data to the clients.

更新

您的设计将三种不同的操作结合在一起.首先,您有数据库读取操作.然后你有数据库更新操作.然后你有数据库通知(或事件).

Your design couples together three distinct kind of operations. First you have the database read operations. Then you have the database update operations. Then you have the database notifications (or events).

这些不同类型的操作要求中的每一种都应该相互分离.这使得整个架构更易于维护和理解.

Each of these different types of operation requirement should be decoupled from each other. This makes the whole architecture easier to maintain and understand.

例如,通过解耦读取操作,您可以决定是否完全使用服务接口.也许可以让您的客户端使用 ADO 直接连接数据库来执行选择操作?

For example, by decoupling the read operations you can make a decision about whether to use a service interface at all. Maybe it's possible to allow your clients to connect directly the database using ADO to perform select operations?

无论如何,无论您是否使用服务,更新操作都应该离线.没有充分的理由将读取和写入操作结合在一起.这还允许您减少数据库争用的可能性,并再次使一切变得简单.客户端向更新队列发送异步更新命令,然后更新服务更新数据库.

At any rate, whether you use a service or not, the update operations should be offlined. There is no good reason to couple together read and write operations. This also allows you to reduce the likelihood of database contention and again keeps everything simple. The client sends asynchronous update commands to the update queue and then the update service updates the database.

这就是我的想法:

这篇关于带有工作线程的 WCF 服务 - 如何设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 18:53:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141293.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   工作   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!