简体   繁体   中英

WCF maxConnections property

I have a WCF service written in .net 4, and exposed over net.tcp. Any time I try to set the MaxConnections property of the binding configuration to something higher than 10 I am AddressAlreadyInUseException.

Why would that be getting thrown on the MaxConnection setting?

(if it matters, I am on Server 2008 R2 Standard with a 4 core CPU and 4 gb ram)

    <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>

Your mex endpoint defines binding configuration which is not part of your configuration snippet.

MaxConnection defines pooling of connections for given port. At the moment you are using two endpoints which share single port - ApiService and Metadata endpoints. Before you changes setting in your binding configuration both enpoints used default value - 10 connections in a pool. When you changed the value it affected only one endpoint second endpoint still demands 10 connections => exception. The solutions are:

  • Expose metadata endpoint on different port.
  • Create custom binding for Mex endpoint. Default mexTcpBinding does not allow changing MaxConnections. Set same value for MaxConnection in custom binding.
  • Try to use port sharing .

At least first idea should work.

<endpoint
        address="mex"
        binding="netTcpBinding" 
        bindingConfiguration="NetTcpBinding"
        contract="IMetadataExchange" />

use binding="netTcpBinding", not mexTcpBinding, so the two endpoints can shahre the same netTcpBinding configuration. The maxConnections value can be the same!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM