问题描述
我最近在我的服务器上安装了新的.NET Framework 4.5(以前是4.0安装),当我启动我的Windows时,我收到一个 System.ServiceModel.AddressAlreadyInUseException
显示WCF端点的服务。
I recently installed the new .NET Framework 4.5 (previously was 4.0 installed) on my Server and I´m getting a System.ServiceModel.AddressAlreadyInUseException
when I start my Windows Service that exposes WCF endpoints.
我的WCF端点的配置如下:
The configuration of my WCF endpoints looks like that:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingConfiguration" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="MEX">
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="MEX" name="MyAssembly.MyNamespace.MyService">
<endpoint address="net.tcp://localhost:56543/MyService"
binding="netTcpBinding" bindingConfiguration="NetTcpBindingConfiguration" contract="MyAssembly.MyNamespace.MyServiceInterface" />
<endpoint address="net.tcp://localhost:56543/MEX" binding="mexTcpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
我认为它与使用相同端口的MEX端点有关,不确定如何在升级到.NET Framework 4.5后正确配置。
I think it has something to do with the MEX endpoint that uses the same port, but I'm not sure how to configure it correctly after upgrading to .NET Framework 4.5.
WCF中是否有更改,这些配置会引发异常?
Was there a change in WCF so that these configuration raises an exception?
推荐答案
这是因为对netTcp端点和mex端点使用相同的端口有一些限制,记录在参考使用NetTcpBinding在服务端点和mex端点之间共享端口。在4.0中, listenBackLog
和 MaxConnections
的默认值为10.在4.5中,这些默认值被修改为12 * ProcessorCount。当您尝试在netTcpBinding和mex端点之间共享端口时,会出现此异常,但前提是这两个属性具有不同的值。在4.0这工作正常,因为你已经设置为默认值(10),因此这些设置在两个端点上没有区别。但在4.5这些留给netTcp端点为10,但计算为12 * ProcessorCount。所以异常。
This is because of some limitations in using the same port for both the netTcp endpoint and mex endpoint documented here refer section "Sharing a port between a service endpoint and a mex endpoint using the NetTcpBinding". In 4.0 the defaults for listenBackLog
and MaxConnections
were 10. In 4.5 these defaults were revised as 12 * ProcessorCount. This exception happens when you try to share a port between netTcpBinding and mex endpoint provided you have different values for these two properties. In 4.0 this worked fine as you have set these to the default values (10) and thus these settings do not differ on both endpoints. But in 4.5 these are left as 10 for netTcp endpoint, but computed as 12* ProcessorCount. So the exception.
要解决此问题,有两种方法:
To solve this issue there are 2 ways:
- 删除这些设置
listenBackLog
和MaxConnections
)。这样,您将自动获得默认值为12 *处理器计数,大于4.0默认值。 - 按照
- Remove these settings (
listenBackLog
andMaxConnections
) from the config. In this way you will get a default of 12 * Processor count automatically which is > than 4.0 defaults. - Follow the work around of configuring mex endpoint on a different port as described in documentation
请检查了解更多详情。
这篇关于升级到.NET 4.5后获取AddressAlreadyInUseException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!