单例的 WCF 服务仅接受一个并发客户端
我有一个单例 WCF 服务,它拥有用于与外部方通信的套接字。我正在使用 .NET 3.5 SP1
该代码是线程安全的并且可扩展性良好。
当我在 Windows 2008 R2 64 位上的 IIS 7.5 托管的 WCF 服务中运行此代码时,WCF 服务无法接受多个并发调用。
我的服务类实现了三个接口,每个接口都有一个标准的 ServiceContract 属性,只有一个命名空间,没有其他设置
我在类上有以下属性:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
我有以下行为配置:
<behavior name="MyServiceAsyncBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceThrottling maxConcurrentCalls="60" maxConcurrentSessions="60"
maxConcurrentInstances="60" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
我创建了一个单独的应用程序,使用了完全相同的配置文件(实际上是一个副本,没有对其进行任何更改),以及一个具有完全相同的 ServiceBehavior 属性的单例服务类。该服务没有表现出相同的行为,它很高兴地允许并发调用。
允许并发调用的测试服务与不允许并发调用的真实服务之间的唯一区别在于,真实服务拥有工作线程和 TCP 套接字,并实现了三个接口而不是一个。
我在这里缺少什么?
I have a singleton WCF service that owns sockets that are used to communicate with an external party. I am using .NET 3.5 SP1
The code is thread safe and scales well.
When I run this code in a WCF service hosted in IIS 7.5 on Windows 2008 R2 64 bit, the WCF service cannot accept more than one concurrent call.
My service class implements three interfaces, each with a standard ServiceContract attribute and only a namespace, no other settings
I have the following attribute on the class:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
I have the following behavior configuration:
<behavior name="MyServiceAsyncBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceThrottling maxConcurrentCalls="60" maxConcurrentSessions="60"
maxConcurrentInstances="60" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
I created a seperate application, used the exact same configuration file (literally a copy, no changes were made to it), and a singleton service class with the exact same ServiceBehavior attribute on the class. This service DOES NOT exhibit the same behavior, it happily allows concurrent calls.
The only differences between the test service that allows concurrent calls and the real service that does not is that the real service owns worker threads and TCP sockets, and implements three interfaces instead of one.
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了这个问题。它涉及到远程TCP服务。我使用了一个行为不当的测试服务,该服务从未返回给调用者。
WCF 似乎阻止了对单例的并发调用,因为单例被锁定在紧密循环中
I found the issue. It relates to the remote TCP service. I was using an ill-behaved test service, which never returned to the caller.
WCF seems to have prevented concurrent calls to the singleton because the singleton was locked in a tight loop