Getting an AddressAlreadyInUseException after upgrading to .NET 4.5

I recently installed a new .NET Framework 4.5 (previously installed on 4.0) on my server, and I get a System.ServiceModel.AddressAlreadyInUseException when I start my Windows service, which provides WCF endpoints.

System.ServiceModel.AddressAlreadyInUseException: A listener already exists on the IP endpoint 0.0.0.0.0656543. This can happen if there is another application already listening on this endpoint, or if you have several service endpoints on your service host with the same IP address but with incompatible binding configurations. ---> System.Net.Sockets.SocketException: only one use of each socket address (protocol / network address / port) is usually allowed on System.Net.Sockets.Socket.DoBind (EndPoint endPointSnapshot, SocketAddress socketAddress) in System.Net. Sockets.Socket.Bind (EndPoint localEP) in System.ServiceModel.Channels.SocketConnectionListener.Listen () --- End of the internal trace of the exception stack System.ServiceModel.Channels.SocketConnectionListener.Listen () at System.ServiceModel.Channels.BufferedConnectionListener.Listener () at System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen ()
in System.ServiceModel.Channels.TransportManager.Open (TransportChannelListener channelListener) in System.ServiceModel.Channels.TransportManagerContainer.Open (SelectTransportManagersCallback.TelportManlagerChannel.TelnelMentelTerrent.elannelTelTenMelTelnelTerNelTerMenelTerNelTerMenelTerNel .. .OnOpen (TimeSpan timeout) in System.ServiceModel.Channels.TcpChannelListener`2.OnOpen (TimeSpan timeout) in System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) in System.ServiceModel.Dispatcher.ChannelOisPer in System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) in System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) in System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) in Qosit.Inererran [] args)

My WCF endpoints configuration looks like this:

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

I think this 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 the .NET Framework 4.5.

Was there a change in WCF so that this configuration throws an exception?

+6
source share
2 answers

This is due to some restrictions on using the same port for the netTcp endpoint and the mex endpoint registered here in the section "Sharing a port between a service endpoint and mex using NetTcpBinding". In 4.0, the default values ​​for listenBackLog and MaxConnections were 10. In 4.5, these default values ​​were redefined as 12 * ProcessorCount. This exception occurs when you try to share a port between netTcpBinding and the mex endpoint if you have different values ​​for these two properties. In 4.0, this worked fine, since you set them to the default values ​​(10), and thus, these settings do not differ from each other at both endpoints. But in 4.5 they are left as 10 for the netTcp endpoint, but are calculated as 12 * ProcessorCount. So, an exception.

To solve this problem, there are 2 ways:

  • Remove these settings ( listenBackLog and MaxConnections ) from the configuration. Thus, you will get the default value equal to 12 * the number of processors, which is> 4.0 by default.
  • Follow the steps to configure the mex endpoint on another port, as described in the documentation

You can learn more about this in this blog .

+16
source

When you host the WCF service in a console application, you need to copy the App.config file from the WCF project to the console application, and then delete the App.config file from the WCF project if you cannot also get the above error.

+1
source

Source: https://habr.com/ru/post/927824/


All Articles