gpt4 book ai didi

.net - WCF maxConnections 属性

转载 作者:行者123 更新时间:2023-12-02 06:16:50 24 4
gpt4 key购买 nike

我有一个用 .net 4 编写的 WCF 服务,并通过 net.tcp 公开。每当我尝试将绑定(bind)配置的 MaxConnections 属性设置为高于 10 的值时,我都会遇到 AddressAlreadyInUseException。

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

(如果重要的话,我使用的是 Server 2008 R2 Standard,具有 4 核 CPU 和 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>

最佳答案

您的 mex 端点定义的绑定(bind)配置不是您的配置片段的一部分。

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

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

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

关于.net - WCF maxConnections 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3689008/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com