简体   繁体   English

如何处理使用数据库的WCF服务中的并发性

[英]How to handle concurrency in WCF service working with a database

Hello :) I am quite new to WCF and this is my first time dealing with concurrency of any kind, so please bear with me. 你好:)我对WCF很新,这是我第一次处理任何类型的并发,所以请耐心等待。

What I want to do is to have a single instance of a service, which will be consumed by multiple clients (no more than 10 or 11). 我想要做的是拥有一个服务的实例,它将被多个客户端使用(不超过10或11)。 I want the clients to wait for each other when they consume the service operations. 我希望客户端在使用服务操作时互相等待。 This way I should avoid incorrect updates of an entry in the data base. 这样我就应该避免对数据库中的条目进行不正确的更新。 The operations are fast enough so that performance should not be affected too much. 操作速度足够快,因此性能不会受到太大影响。 Now Im not sure, but to my understanding, to achieve that I should use a singleton service with ConcurrencyMode.Single, is that right ? 现在我不确定,但据我的理解,要实现这一点,我应该使用ConcurrencyMode.Single的单件服务,是吗? Any comprehensive read on how to achieve that goal is welcome. 任何关于如何实现这一目标的全面阅读都是受欢迎的。

Also Im aware that there may be better and more elegant ways of handling concurrency, but Im very very short on time, and this method seems the simplest and fastest one to implement, if I have understood it correctly that is. 我也意识到可能有更好,更优雅的方式处理并发,但我的时间非常短,这个方法似乎是最简单和最快的实现,如果我已经正确理解它。

The worst you can do here is a singleton service. 你可以做的最糟糕的是单身人士服务。

Database engines (well, most of them) are well-suited for concurrent calls. 数据库引擎(大多数)非常适合并发调用。 What do you want to restrict their concurrent features for? 你想要限制他们的并发功能是什么?

The best way for you is a per-call, stateless WCF service. 最适合您的方式是每次呼叫,无状态WCF服务。
For data consistency, use optimistic concurrency . 为了数据一致性,请使用乐观并发 To simplify this you can use any ORM, like Entity Framework . 为简化此操作,您可以使用任何ORM,例如Entity Framework

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM