【问题标题】:WCF maxConnections propertyWCF maxConnections 属性
【发布时间】:2013-12-02 12:21:20
【问题描述】:

我有一个用 .net 4 编写的 WCF 服务,并通过 net.tcp 公开。每当我尝试将绑定配置的 MaxConnections 属性设置为高于 10 的时候,我就是 AddressAlreadyInUseException。

为什么会在 MaxConnection 设置中出现这种情况?

(如果重要的话,我使用的是具有 4 核 CPU 和 4 GB 内存的 Server 2008 R2 Standard)

    <binding name="NetTcpBinding" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          transferMode="Buffered" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxBufferSize="25000000"
          maxReceivedMessageSize="25000000" maxConnections="50">
          <readerQuotas maxDepth="32" maxStringContentLength="25000000"
            maxArrayLength="25000000" maxBytesPerRead="25000000" maxNameTableCharCount="25000000" />
          <security mode="None" />
    </binding>

    <service behaviorConfiguration="ApiService.ServiceBehavior" name="Api.Service.PlatformApiService">
      <endpoint
        address="/Search"
        binding="netTcpBinding"
        bindingConfiguration="NetTcpBinding"
        contract="IApiService" />        
      <endpoint
        address="mex"
        binding="mexTcpBinding"
        bindingConfiguration="NetTcpBinding"
        contract="IMetadataExchange" />

      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8094/Api/" />
        </baseAddresses>
      </host>
    </service>

【问题讨论】:

    标签: .net wcf


    【解决方案1】:

    您的 mex 端点定义了不属于您的配置 sn-p 的绑定配置。

    MaxConnection 定义给定端口的连接池。目前,您正在使用共享单个端口的两个端点 - ApiService 和元数据端点。在您更改绑定配置中的设置之前,两个端点都使用默认值 - 池中的 10 个连接。当您更改值时,它只影响一个端点,第二个端点仍然需要 10 个连接 => 异常。解决方案是:

    • 在不同的端口上公开元数据端点。
    • 为 Mex 端点创建自定义绑定。默认 mexTcpBinding 不允许更改 MaxConnections。在自定义绑定中为 MaxConnection 设置相同的值。
    • 尝试使用port sharing

    至少第一个想法应该可行。

    【讨论】:

    • 我可以确认您的第二个和第三个建议也有效,尽管我认为第二个工作更少/更优雅。
    【解决方案2】:
    <endpoint
            address="mex"
            binding="netTcpBinding" 
            bindingConfiguration="NetTcpBinding"
            contract="IMetadataExchange" />
    

    使用 binding="netTcpBinding",而不是 mexTcpBinding,因此两个端点可以共享相同的 netTcpBinding 配置。 maxConnections 值可以相同!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-31
      • 2011-02-04
      • 2013-08-31
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      相关资源
      最近更新 更多