简体   繁体   English

如何解决 C# IIS 托管 WCF NET TCP 服务超时问题

[英]How to troubleshoot C# IIS-hosted WCF NET TCP service timeout issues

I have inherited a C# web service hosted by IIS on Windows Server 2019 that is having a problem that I'm struggling to track down.我继承了 C# web 服务,该服务由 ZAEA23489CE3AA9B6406EB208E0CDA401 上的 IIS 托管,该服务器正在努力追踪问题。

The WCF service listens on port 82 for http connections, and on port 8002 for net tcp connections; WCF 服务在端口 82 上侦听 http 连接,在端口 8002 上侦听网络 tcp 连接; the IIS config for the site has it's Bindings set to http:*:82:,net.tcp:8002:*该站点的 IIS 配置将其绑定设置为http:*:82:,net.tcp:8002:*

However, when the service has been running for a few hours it stops responding on the net tcp port (8002) - other apps that attempt to connect to it end up timing out:但是,当服务运行几个小时后,它会在网络 tcp 端口 (8002) 上停止响应 - 其他尝试连接到它的应用程序最终会超时:

System.TimeoutException: The open operation did not complete within the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The socket transfer timed out after 00:01:00. You have exceeded the timeout set on your binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Yet connections to the http port (82) still work as expected, so the service is still running.然而,与 http 端口 (82) 的连接仍按预期工作,因此服务仍在运行。

Recycling the appropriate app pool causes the net tcp connections to start working properly again, which suggests to me that it might be some sort of resource leak, but I can see nothing obvious in the code, and it doesn't appear to be a lack of memory.回收适当的应用程序池会导致网络 tcp 连接再次开始正常工作,这对我来说可能是某种资源泄漏,但我在代码中看不到任何明显的东西,而且似乎并不缺乏memory。

I'm at a loss as to how to troubleshoot this further - any suggestions?我不知道如何进一步解决这个问题 - 有什么建议吗?

According to your description, the problem may be that the number of connected clients exceeds the maximum capacity of the server-side, and the server can't handle it.根据你的描述,问题可能是连接的客户端数量超过了服务器端的最大容量,服务器处理不了。 If the client-side waits for a timeout, the TimeoutException will appear.如果客户端等待超时,就会出现 TimeoutException。

You can view the maximum number of connections for the service through the following code:您可以通过以下代码查看该服务的最大连接数:

        NetTcpBinding binding = new NetTcpBinding();
        Console.WriteLine(binding.MaxConnections);

This is a reference link for maxconnections:这是 maxconnections 的参考链接:

https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.nettcpbinding.maxconnections?view=netframework-4.8 https://docs.microsoft.com/en-us/dotnet/api/system.servicemodel.nettcpbinding.maxconnections?view=netframework-4.8

There is servicethrottling property in WCF service, which specifies the restriction mechanism of windows communication foundation (WCF) service. WCF服务中有servicethrottling属性,指定了windows通信基础(WCF)服务的限制机制。 You can prevent excessive consumption of resources by setting serviceThrottling in the service.您可以通过在服务中设置 serviceThrottling 来防止过度消耗资源。

The following configuration example specifies that the service limits the maximum concurrent calls to 2, and the maximum number of concurrent instances to 10.以下配置示例指定服务将最大并发调用数限制为 2,将最大并发实例数限制为 10。

在此处输入图像描述

In order to prevent excessive consumption of resources, the channel needs to be closed after each call by the client-side.为了防止过度消耗资源,客户端每次调用后都需要关闭通道。

       ServiceReference1.Service1Client service1Client = new ServiceReference1.Service1Client();
        service1Client.GetData(0);
        service1Client.Close();

For more information about serviceThrottling, please refer to the following link:有关 serviceThrottling 的更多信息,请参考以下链接:

https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/wcf/servicethrottling https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/wcf/servicethrottling

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

相关问题 从Linux Web应用程序中使用IIS托管的WCF服务 - Consuming IIS-hosted WCF Service from Linux Web Application IIS托管的WCF REST服务-JSON将枚举序列化为字符串 - IIS-Hosted WCF REST service - JSON serialize enum as string 如何解决 IIS 托管的 WCF 服务中超出的 MaxConcurrentSessions - How to troubleshoot MaxConcurrentSessions exceeded in IIS hosted WCF Service 应如何将 IIS 托管的基于 ASP.Net 的系统部署到 Azure Service Fabric? - How should IIS-hosted ASP.Net-based systems be deployed to Azure Service Fabric? 使用MS Sync Framework和IIS托管的WCF服务将带有2mb条目的表同步 - Synchronizing table with 2mb entry with MS Sync Framework and IIS-Hosted WCF Service takes 10 minutes 无法解决在原始IIS托管的WCF示例中的错误:找不到作为服务属性值[...]提供的类型[…] - Cannot resolve error in vanilla IIS-hosted WCF example: The type […] provided as the Service attribute value […] could not be found 如何使用Delphi 2007中的非IIS托管,WCF,C#Web服务? - How to consume non-IIS hosted, WCF, C# web service from Delphi 2007? 如何将文件上传到IIS中托管的.NET 3.5 WCF服务? - How to upload a file to a .NET 3.5 WCF service hosted in IIS? 无法从IIS托管的应用程序连接到远程REST服务 - Unable to connect to the remote REST service from the IIS-hosted application IIS问题上的WCF net.tcp服务 - WCF net.tcp service on IIS issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM