ConcurrencyMode为Single时可以调用多个操作合约吗

发布于 2024-12-04 10:46:24 字数 161 浏览 4 评论 0原文

我有一个带有 3 个操作合同的 WCF 服务。我为此服务设置了[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)]。我的基本疑问是我是否可以一次调用所有 3 个服务,或者一次只能调用一个合约。请哪位高人给个解决方案。

I have a WCF service with 3 operation contracts. I set [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single)] for this service. My basic doubt is can I able to call all the 3 service at a time or only one contracts can be called at once. Please can any one give a solution.

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

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

发布评论

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

评论(1

情话已封尘 2024-12-11 10:46:24

并发模式具有实例上下文模式的范围。如果将 ConcurrencyMode 设置为 Single,您只需告诉 WCF 每个服务实例只能处理一个并发请求 - Single 也是 的默认值>并发模式

除非您将 InstanceContextMode 也配置为 Single(= 您将使服务成为单例),否则您的服务主机将为每个请求生成新的服务实例(无状态绑定,例如 BasicHttpBindingWebHttpBinding)或每个连接的代理(有状态绑定,例如 NetTcpBindingNamedPipeBindingWsHttpBinding 的一些配置)。在前一种情况下,ConcurrencyMode 没有任何效果,因为每个服务实例仅用于处理单个请求=可以同时处理来自任意数量客户端的请求。在后面的情况下,ConcurrencyMode.Single 告诉我们按顺序处理来自单个客户端代理的请求,但可以同时处理来自多个客户端代理的请求。每个公开的合约都需要单独的端点,并且客户端上的每个使用的端点都需要单独的代理实例,因此在这种情况下,每个合约的代理将具有单独的服务实例。

根据您当前的配置,只有服务限制可以控制可以使用您的服务的并发客户端数量。

一旦您将 InstanceContextMode 也设置为 Single,您确实将拥有一次只能处理单个请求的服务。已实现的合约数量并不重要,因为在本例中,单个服务上的端点中公开的所有合约均由仅接受一个并发请求的单个服务实例处理。

Concurrency mode has scope for instance context mode. If you set ConcurrencyMode to Single you just tell WCF that each service instance can handle only one concurrent request - Single is also default value for ConcurrencyMode.

Unless you configure InstanceContextMode to Single as well (= you will make your service singleton) your service host will spawn new service instance either for each request (stateless bindings like BasicHttpBinding or WebHttpBinding) or for each connected proxy (statefull bindings like NetTcpBinding, NamedPipeBinding and some configurations of WsHttpBinding). In the former case ConcurrencyMode doesn't have any effect because each service instance is used only to handle single request = requests from any number of clients can be handled concurrently. In later case ConcurrencyMode.Single tells that requests from single client proxy are handled in sequential order but requests from multiple client proxies can be handled concurrently. Each exposed contract requires separate endpoint and each consumed endpoint on a client requires separate proxy instance so proxy for each contract will have separate service instance in this case.

With your current configuration only service throttling controls how many concurrent clients can consume your service.

Once you set InstanceContextMode to Single as well you will indeed have the service which will be able to handle only single request at one time. The number of implemented contracts doesn't matter because all contracts exposed in endpoints on single service are in this case handled by single service instance which accepts only one concurrent request.

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