c# - 请求在 WCF IIS 服务器中堆积

标签 c# wcf iis

我们在服务中使用 BasicHttpBinding 并且我们将并发模式设置为多个,实例上下文模式设置为单个,如下所示

 [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
 ConcurrencyMode =ConcurrencyMode.Multiple)]
public class Service1 : IService1

我们已经通过引用在控制台中使用了这个服务。我们遇到了一个问题,一段时间后我们看到消息堆积在 IIS 工作进程中。

例如 -> 在 1 分钟内,它在 IIS 的工作进程中显示为只有一个线程,但一段时间后我们在 IIS 中看到多个请求?

任何人都可以在这里提供帮助,比如为什么一段时间后我们看到消息在 IIS 中排队?

下面是配置中的绑定(bind)

<binding name="BasicHttpBinding_Common" 
        closeTimeout="00:10:00" openTimeout="00:10:00" 
        receiveTimeout="00:10:00" sendTimeout="00:10:00" 
        allowCookies="false" bypassProxyOnLocal="false" 

enter image description here

最佳答案

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
 ConcurrencyMode =ConcurrencyMode.Multiple)]

Specifies the number of service instances available for handling calls that are contained in incoming messages: InstanceContextMode.Single -Only one InstanceContext object is used for all incoming calls and is not recycled subsequent to the calls. If a service object does not exist, one is created.

Specifies whether a service class supports single-threaded or multi-threaded modes of operation: ConcurrencyMode.Multiple - The service instance is multi-threaded. No synchronization guarantees are made. Because other threads can change your service object at any time, you must handle synchronization and state consistency at all times. It is your responsibility to guard your state with locks. The service implementation must be thread-safe to use this concurrency mode.

您可以尝试将 UseSynchronizationContext = false 添加到您的 ServiceBehavior。如果这没有帮助,您可以尝试将 ReleaseServiceInstanceOnTransactionComplete=truefalse 添加到您的 ServiceBehavior。如果 InstanceContextMode 是多个,我不确定您是否可以设置为 true。

由于使用 ConcurrencyMode.Multiple 没有做出同步保证,并且 UseSynchronizationContext 的默认值为 true,它可能会尝试处理导致队列的同一线程上的所有调用。

您用来调用该服务的代码也可能存在一些问题。如果不亲眼所见,我们将一无所知。

为每次调用启动一个线程可能只需要一点时间??在你的图片中,最长的请求只有 5.5 秒。 (我知道这对于一个简单的电话来说很长。)

这也可能是无意义的:https://stackoverflow.com/a/4698956/2016162

关于c# - 请求在 WCF IIS 服务器中堆积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53920332/

相关文章:

iis - 我应该如何将排队的邮件从 IIS 移动到不同服务器上的 Exchange?

c# - 从 ASP.NET 网站获取 IIS 站点名称

iis - 更新配置文件中的 IIS 绑定(bind),而不是 GUI

c# - 匹配文本中重复部分的正则表达式

c# - 无法使用 powershell 远程启动 WCFapplication (System.ServiceModel)

wcf - 无法连接到辅助角色中托管的 WCF 服务

c# - WCF 数据对象接收进度

c# - Entity Framework : Duplicate Records in Many-to-Many relationship

c# - Visual Studio 2013 中的 ClickOnce 没有网页发布选项

c# - 系统.安全.SecurityException : That assembly does not allow partially trusted callers