[英]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.