gpt4 book ai didi

wcf - 升级到.NET 4.5后获取AddressAlreadyInUseException

转载 作者:行者123 更新时间:2023-12-04 13:17:07 24 4
gpt4 key购买 nike

我最近在服务器上安装了新的.NET Framework 4.5(以前安装了4.0),并且在启动公开WCF终结点的Windows服务时得到了System.ServiceModel.AddressAlreadyInUseException

System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:56543. This could happen if there is another application already listening on this endpoint or if you have multiple service endpoints in your service host with the same IP endpoint but with incompatible binding configurations. ---> System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at System.ServiceModel.Channels.SocketConnectionListener.Listen() --- End of inner exception stack trace --- at System.ServiceModel.Channels.SocketConnectionListener.Listen() at System.ServiceModel.Channels.BufferedConnectionListener.Listen() at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener) at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback) at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.ConnectionOrientedTransportChannelListener.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at Qosit.Infrastructure.UnisServer.OnStart(String[] args)



我的WCF端点的配置如下所示:
<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后如何正确配置它。

WCF是否进行了更改,以使这些配置引发异常?

最佳答案

这是由于在here中记录的netTcp端点和mex端点使用同一端口方面存在一些限制,请参见“使用NetTcpBinding在服务端点和mex端点之间共享端口”一节。在4.0中,listenBackLogMaxConnections的默认值为10。在4.5中,这些默认值修改为12 * ProcessorCount。当您尝试在netTcpBinding和mex端点之间共享端口时,如果您对这两个属性使用不同的值,则会发生此异常。在4.0中,这很好,因为您已将它们设置为默认值(10),因此这些设置在两个端点上都没有区别。但是在4.5中,对于netTcp端点,这些保留为10,但计算为12 * ProcessorCount。所以异常(exception)。

要解决此问题,有两种方法:

  • 从配置中删除这些设置(listenBackLogMaxConnections)。这样,您将自动获得默认值12 *处理器数,该值大于默认值4.0。
  • 按照documentation
  • 中所述在其他端口上配置mex端点的解决方法

    请查看 this blog了解更多详细信息。

    关于wcf - 升级到.NET 4.5后获取AddressAlreadyInUseException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12911860/

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