Search code examples
c#wcfconnection-pooling

How to increase or disable WCF pooling limit?


I have the following code to setup a WCF service in code:

namespace Serviceman
{
public class Hostman
{

    public Uri VServicesTCPAddress = new Uri("net.tcp://localhost:8000/v-services");
    public ServiceHost VServicesHost = new ServiceHost(typeof(MyDemoService), new Uri("net.tcp://localhost:8000/v-services"));

    public void ConfigureTcpService()
    {
        NetTcpBinding tcpBinding = new NetTcpBinding();
        ServiceMetadataBehavior sMBehavior = new ServiceMetadataBehavior();
        VServicesHost.Description.Behaviors.Add(sMBehavior);
        VServicesHost.AddServiceEndpoint(typeof(IMetadataExchange),
        MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
        VServicesHost.AddServiceEndpoint(typeof(IAccountsService), tcpBinding, VServicesTCPAddress);
    }

}

}

I have started the service and it's working just fine, but when I connect multiple instances of my client, after some time I receive errors of having used all available channels. The question now is how can I increase the default value for connection pooling limit or even remove that?


Solution

  • Enable port sharing on your TCP binding like this,

    tcpBinding.PortSharingEnabled = true;
    

    Or,

    Change maxConnections available on your TCP binding configuration to something of your choice.The default for Max connection is 10 out of the box.