如何增加或禁用WCF池限制?

时间:2014-11-24 01:56:04

标签: c# wcf connection-pooling

我有以下代码在代码中设置WCF服务:

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);
    }

}

}

我已启动该服务并且它工作正常,但是当我连接我的客户端的多个实例时,一段时间后我收到使用所有可用频道的错误。现在的问题是如何增加连接池限制的默认值,甚至删除它?

1 个答案:

答案 0 :(得分:0)

在TCP绑定上启用端口共享,如下所示,

tcpBinding.PortSharingEnabled = true;

或者,

maxConnections上的TCP binding configuration更改为您选择的内容.Max连接的默认值为10开箱即用。