netTcpBinding - regression in default values for listenBacklog and maxConnections?

Joseph Benken 1 Reputation point
2022-06-22T23:59:30.283+00:00

In a .NET WCF client configuration file, netTcpBinding has various configuration attributes including listenBacklog and maxConnections. If you were to omit these two attributes from the netTcpBinding/binding element then default values should be used which is supposed to be 10:
https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.configuration.nettcpbindingelement.listenbacklog
https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.configuration.nettcpbindingelement.maxconnections

For example, if I create a new .NET WCF client config file in the Microsoft Service Configuration Editor (SvcConfigEditor.exe) and create a new binding configuration of type "netTcpBinding", then you see they are 10 by default:
213967-image.png

However, that last screenshot was taken on an old release of .NET. On the current release of .NET Framework 4.8 on Windows 10 the default for both of those option unexpectedly changed from 10 to 0:
213976-image.png

This is not an issue in the Microsoft Service Configuration Editor but what looks like a regression in .NET WCF itself. I am just using the Microsoft Service Configuration Editor to illustrate the problem. I do not know exactly what version or update of .NET Framework this broke, only that this is broken in the current release of .NET Framework 4.8.

In my case I am actually writing an application in C#, using System.ServiceModel.Configuration API to read settings from a .NET config file. The ListenBacklog and MaxConnections properties of my NetTcpBindingElement object are now unexpectedly set to 0 instead of 10. I am not sure exactly which version of .NET this broke and I see no issue with NetTcpBindingElement returning correct defaults for other properties.

To work around the issue, I must edit my .NET WCF client config file and explicitly add both "listenBacklog" and "maxConnections" XML attributes with value set to a positive integer. Otherwise, if the attributes are absent then 0 (instead of 10) is incorrectly returned from the NetTcpBindingElement object. A value of 0 is definitely illegal. If I were to actually set 0 for either of these properties on a NetTcpBinding object then I get a System.ArgumentOutOfRangeException "The value of this argument must be positive." being thrown when setting the ListenBacklog or MaxConnections properties.

Can someone shed any light on this issue? This really looks like something broke in some update of .NET WCF, especially given that all other config properties for NetTcpBindingElement are still returning the correct default values as expected.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,649 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 28,841 Reputation points Microsoft Vendor
    2022-06-24T02:51:48.46+00:00

    Hi @Joseph Benken ,
    I think I checked your code and found the problem.
    The default value for ListenBacklog and MaxConnections is 10, as you can see from the screenshot. (I am testing in .NET Framework 4.8).
    214534-1.jpg
    You can try the following code:

     void ConfigureNetTcpBinding(NetTcpBinding binding, NetTcpBindingElement config) {  
                config.Name = binding.Name;  
                config.ListenBacklog = binding.ListenBacklog;  
                config.MaxConnections = binding.MaxConnections;  
                config.MaxBufferPoolSize = binding.MaxBufferPoolSize;  
                config.MaxBufferSize = binding.MaxBufferSize;  
             }  
    

    You can take a look at the description in the documentation:
    ListenBacklog: Gets or sets a value that specifies the maximum number of channels that can wait to be accepted on the listener.
    This example shows how to get the ListenBacklog value.
    int listenBacklog = binding.ListenBacklog;
    https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.configuration.nettcpbindingelement?view=netframework-4.8
    https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.nettcpbinding.listenbacklog?view=netframework-4.8#examples
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.