ConcurrencyMode为Single时可以调用多个操作合约吗
我有一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并发模式具有实例上下文模式的范围。如果将
ConcurrencyMode
设置为Single
,您只需告诉 WCF 每个服务实例只能处理一个并发请求 -Single
也是的默认值>并发模式
。除非您将 InstanceContextMode 也配置为 Single(= 您将使服务成为单例),否则您的服务主机将为每个请求生成新的服务实例(无状态绑定,例如
BasicHttpBinding
或WebHttpBinding
)或每个连接的代理(有状态绑定,例如NetTcpBinding
、NamedPipeBinding
和WsHttpBinding
的一些配置)。在前一种情况下,ConcurrencyMode 没有任何效果,因为每个服务实例仅用于处理单个请求=可以同时处理来自任意数量客户端的请求。在后面的情况下,ConcurrencyMode.Single 告诉我们按顺序处理来自单个客户端代理的请求,但可以同时处理来自多个客户端代理的请求。每个公开的合约都需要单独的端点,并且客户端上的每个使用的端点都需要单独的代理实例,因此在这种情况下,每个合约的代理将具有单独的服务实例。根据您当前的配置,只有服务限制可以控制可以使用您的服务的并发客户端数量。
一旦您将 InstanceContextMode 也设置为 Single,您确实将拥有一次只能处理单个请求的服务。已实现的合约数量并不重要,因为在本例中,单个服务上的端点中公开的所有合约均由仅接受一个并发请求的单个服务实例处理。
Concurrency mode has scope for instance context mode. If you set
ConcurrencyMode
toSingle
you just tell WCF that each service instance can handle only one concurrent request -Single
is also default value forConcurrencyMode
.Unless you configure
InstanceContextMode
toSingle
as well (= you will make your service singleton) your service host will spawn new service instance either for each request (stateless bindings likeBasicHttpBinding
orWebHttpBinding
) or for each connected proxy (statefull bindings likeNetTcpBinding
,NamedPipeBinding
and some configurations ofWsHttpBinding
). In the former caseConcurrencyMode
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 caseConcurrencyMode.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
toSingle
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.