Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何增加或禁用WCF池限制?_C#_Wcf_Connection Pooling - Fatal编程技术网

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

C# 如何增加或禁用WCF池限制?,c#,wcf,connection-pooling,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://l

我使用以下代码在代码中设置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);
    }

}

}

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

像这样在TCP绑定上启用端口共享

tcpBinding.PortSharingEnabled = true;
或者


TCP绑定配置中可用的
maxConnections
更改为您选择的内容。Max connection的默认值为10开箱即用。

服务使用者是否在收到响应后立即关闭连接?如果没有,那么在超时(可能是几分钟)之前,连接将无法重新使用。当然没有,我还没有将其编码为关闭,以为WCF会解决这个问题。因此,如果我关闭它们,是否有可能再次面临错误?我以与SQL连接相同的方式查看WCF连接,即尽可能快地关闭它们。请参阅Enrico Campidoglio的答案,了解我认为您应该如何为客户编写代码。顺便说一句,我相信默认的WCF最大并发会话数是100 x服务器处理器数(假设您使用IIS,您应该能够通过IIS管理器检查此情况)。那么,“maxConnections”是连接到服务的所有客户端的一般限制还是每个客户端都有自己的连接数?我的意思是,如果我将其设置为100,那么这是所有客户的限制还是每个客户都得到100?