IP端点0.0.0.0:13000上已经有一个监听器。 ?? (使用WCF的TCP)

我试图找出为什么即使在重新启动计算机后使用该端口!

System.ServiceModel.AddressAlreadyInUseException:IP端点0.0.0.0:13000上已有一个侦听器。 如果另一个应用程序已经在此端点上侦听,或者您的服务主机中有多个具有相同IP端点但具有不兼容的绑定configuration的服务端点,则可能会发生这种情况。 —> System.Net.Sockets.SocketException:System上的System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,SocketAddress socketAddress)通常只允许使用每个套接字地址(协议/networking地址/端口)。 Net.Sockets.Socket.Bind(EndPoint localEP)在System.ServiceModel.Channels.SocketConnectionListener.Listen()—内部exception堆栈跟踪结束—在系统的System.ServiceModel.Channels.SocketConnectionListener.Listen()。 System.ServiceModel.Channels.ConnectionAcceptor.StartAccepting()System.ServiceModel.Channels.ExclusiveTcpTransportManager.OnOpen()上的System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)上的ServiceModel.Channels.TracingConnectionListener.Listen()。 ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)at System.ServiceModel.Channels.TcpChannelListener`2.OnOpen(TimeSpan timeout)at System.ServiceModel.Channels.Communicat 在System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan超时)在System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan超时)上的ionObject.Open(TimeSpan超时)。 ServiceModel.Channels.CommunicationObject.Open(TimeSpan超时)在Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo信息)System.Net.Sockets.SocketException(0x80004005):每个套接字地址(协议/networking地址/端口)通常允许在System.Net.Sockets.Bind(EndPoint localEP)上的System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,SocketAddress socketAddress)在System.ServiceModel.Channels.SocketConnectionListener.Listen()

你如何找出哪个进程在监听那个端口(13000)? Netstat在该端口上没有显示任何内容。

这是我的App.config:

<system.web> <compilation debug="true" /> </system.web> <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel> <services> <service name="SomeTarget.SomeTargetService"> <endpoint address="" binding="customBinding" bindingConfiguration="NetTcpBinding" contract="SomeTarget.ISomeTargetService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:13000" /> </baseAddresses> </host> </service> </services> <bindings> <customBinding> <binding name="NetTcpBinding" sendTimeout="00:05:00" closeTimeout="00:00:30" openTimeout="00:00:30" receiveTimeout="00:05:00"> <transactionFlow /> <binaryMessageEncoding /> <windowsStreamSecurity protectionLevel="None" /> <tcpTransport maxBufferPoolSize="524288" maxReceivedMessageSize="1024" maxBufferSize="1024" > <connectionPoolSettings groupName="default" leaseTimeout="00:05:00" idleTimeout="00:02:00" maxOutboundConnectionsPerEndpoint="20" /> </tcpTransport> </binding> </customBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 

安装.Net 4.5之后,我遇到了这个问题,并且在这里发布一个解决方案来帮助别人,如果他们偶然发现的话。 @ berkayk的答案上面的工作(暴露mex在不同的端口),但我需要通过同一端口公开两个端点。

假设你有两个端点,一个使用netTcpBinding,一个使用mexTcpBinding。 当使用默认的绑定时,一些默认值是使用OSEnvironmentHelper.ProcessorCount来计算的,而不是像.NET 4.0那样的硬编码值。

在我的情况下,当使用命名的netTcpBinding bindingConfiguration时,为MaxConnections属性提供的值为20.设置NetTcpBinding上的MaxConnections属性还将其TcpTransportBindingElement的MaxPendingConnections属性和TcpTransport的ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint属性设置为相同的值。

如果不使用命名的netTcpBinding bindingConfiguration,并且仅使用默认值,则使用以下算法计算MaxPendingConnections属性:

  return (12 * OSEnvironmentHelper.ProcessorCount); 

mexTcpBinding的传输也使用上面的算法计算出它的MaxPendingConnections属性,所以当两者都没有使用命名的bindingConfiguration时,默认值匹配并且没有问题。

使用命名的netTcpBinding bindingConfiguration时,传输的MaxPendingConnections为20,mexTcpBinding的传输MaxPendingConnections在我的机器上为96.这两个端点之间共享相同端口的MaxPendingConnections的值的差异是不兼容的。

我还发现这个问题也是在listnBacklog集合中发生的。 (我不知道可能存在的所有可能的冲突的价值。)

要解决此问题,可以为与netTcpBinding的指定bindingConfiguration匹配的mex创建自定义绑定。 示例如下:

 <endpoint binding="netTcpBinding" bindingConfiguration="TestNetTcpBinding" contract="YourContract" /> <endpoint address="mex" binding="customBinding" bindingConfiguration="TestMexBinding" contract="IMetadataExchange" /> <bindings> <customBinding> <binding name="TestMexBinding"> <tcpTransport maxPendingConnections="20" listenBacklog="20"> <connectionPoolSettings groupName="default" maxOutboundConnectionsPerEndpoint="20" /> </tcpTransport> </binding> </customBinding> <netTcpBinding> <binding name="TestNetTcpBinding" listenBacklog="20" maxConnections="20"/> </netTcpBinding> </bindings> 

或者,您不能指定任何计算的值(如maxConnections和listenBacklog)并接受默认值(请注意,MaxOutboundConnectionsPerEndpoint仍将保留默认值10,因为它的计算方式与MaxPendingConnections属性的计算方式不同):

 <binding name="TestNetTcpBinding" ...someOtherProperties except listenBacklog and maxConnections/> 

注意:这里描述的问题是: http : //msdn.microsoft.com/en-us/library/aa702636.aspx ,但是唯一给出的解决方案是在另一个端口上公开mex。 以下是反射器中的一些屏幕截图,显示了在计算MaxPendingConnections默认值时.net 4.0和4.5之间的区别:

.Net 4.0 ConnectionOrientedTransportBindingElement计算默认的MaxPendingConnections

.Net 4.5 ConnectionOrientedTransportBindingElement计算默认的MaxPendingConnections

.Net 4.5 GetMaxPendingConnections方法

在安装Visual Studio 2012进行评估后,我遇到了同样的问题。 看来,正常的服务和mex服务不能共享相同的端口,因为它曾经在.NET 4.0中使用相同的配置文件(我不知道为什么,必须有一个原因)。 简而言之,我有一个不同的程序集上的服务客户端引用和另一个程序集上的wpf应用程序。 我用不同的端口发布了mex

 <service name="X.XService.XService" behaviorConfiguration="myServiceBehavior"> <endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IXService" contract="X.XService.IXService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="net.tcp://localhost:9103/XService/mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:9102/XService" /> </baseAddresses> </host> </service> 

我的服务引用程序集配置

 <endpoint address="net.tcp://localhost:9103/XService/mex" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IXService" contract="XService.IXService" name="NetTcpBinding_IXService"> <identity> <dns value="localhost" /> </identity> </endpoint> 

最后是我的客户端应用程

  <endpoint address="net.tcp://localhost:9102/XService" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IXService" contract="XService.IXService" name="NetTcpBinding_IXService" behaviorConfiguration="endPointBehavior"> <identity> <dns value="localhost" /> </identity> </endpoint> 

netsat -anb (需要管理员权限)会告诉你什么是在所有的端口上监听…如果没有显示任何东西,你可能有一个错误,你试图创建端点不止一次。

你确定你的服务是唯一一个听13000端口的吗?

运行netstat -noa | find "13000" 在开始程序之前netstat -noa | find "13000" ,以确定哪个进程打开了端口13000。 最右边的列中的数字将是进程ID。

然后运行tasklist | find "<pid>" tasklist | find "<pid>"其中是前一个命令的进程ID。 这将告诉你哪个进程打开13000。

你有.Net框架4.5测试版安装? 在4.5版本的机器上运行时,我看到了同样的错误,而它在4.0上完美运行。 但是,如果我删除mex端点,它再次工作。

在我的情况下,4.5更改中的某些内容会导致相同的错误消息。 也许是一个自动mex端点被创建或什么的。

没有看到任何其他应用程序使用该端口,netstat什么都没有显示。 所以这是某种自我否定…

那么…我的工作,当我将目标框架更改为.Net框架4客户端配置文件。

试试吧…希望它也适用于你!