C# IP 端点 0.0.0.0:13000 上已经有一个侦听器。?? (TCP 使用 WCF)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9744683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
There is already a listener on IP endpoint 0.0.0.0:13000. ?? (TCP using WCF)
提问by LB.
I'm trying to figure out why the port is being used even after restarting the computer!
我试图弄清楚为什么即使在重新启动计算机后仍在使用该端口!
System.ServiceModel.AddressAlreadyInUseException: There is already a listener on IP endpoint 0.0.0.0:13000. 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.TracingConnectionListener.Listen() at System.ServiceModel.Channels.ConnectionAcceptor.StartAccepting() 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.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 Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info) System.Net.Sockets.SocketException (0x80004005): 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()
System.ServiceModel.AddressAlreadyInUseException: IP 端点 0.0.0.0:13000 上已经有一个侦听器。如果有另一个应用程序已经在侦听此端点,或者如果您的服务主机中有多个服务端点具有相同的 IP 端点但绑定配置不兼容,则可能会发生这种情况。---> System.Net.Sockets.SocketException:在 System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) 通常只允许使用每个套接字地址(协议/网络地址/端口)一次。 Net.Sockets.Socket.Bind(EndPoint localEP) 在 System.ServiceModel.Channels.SocketConnectionListener.Listen() --- 内部异常堆栈跟踪结束 --- 在 System.ServiceModel.Channels.SocketConnectionListener.Listen() 在 System.服务模型。
How do you figure out which process is listening to that port (13000)? Netstat shows nothing on that port.
您如何确定哪个进程正在侦听该端口(13000)?Netstat 在该端口上没有显示任何内容。
Here's my App.config:
这是我的 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>
回答by Yaur
netsat -anb(requires admin privileges) will tell you what is listening on all ports... if that shows nothing you probably have a bug where you are trying to create the endpoint more than once.
netsat -anb(需要管理员权限)会告诉您正在侦听所有端口的内容......如果没有显示任何内容,您可能有一个错误,您尝试多次创建端点。
回答by villecoder
Are you sure your service is the only one listening to port 13000?
您确定您的服务是唯一监听端口 13000 的服务吗?
Run netstat -noa | find "13000"before starting your program to identify which process has port 13000 open. The number in the far right-hand column will be the process ID.
netstat -noa | find "13000"在启动程序之前运行以确定哪个进程打开了端口 13000。最右侧列中的数字将是进程 ID。
Then run tasklist | find "<pid>"where is the ID of the process from the previous command. This will tell you which process has 13000 open.
然后tasklist | find "<pid>"从上一个命令运行where 是进程的 ID。这将告诉您哪个进程打开了 13000。
回答by Per Salmi
Do you have .Net Framework 4.5 beta installed? I have seen the same error when running on machines with 4.5 while it ran perfectly on 4.0. But then it works again if I remove the mex endpoint.
您是否安装了 .Net Framework 4.5 测试版?我在 4.5 的机器上运行时看到了同样的错误,而它在 4.0 上运行得很好。但是,如果我删除 mex 端点,它会再次工作。
In my case something in the 4.5 changes caused the same error message. Maybe an automatic mex endpoint was created or something.
在我的情况下,4.5 更改中的某些内容导致了相同的错误消息。也许创建了一个自动 mex 端点或其他东西。
Did not see any other app using the port either, netstat showed nothing. So it was some kind of self-denial...
也没有看到任何其他应用程序使用该端口,netstat 什么也没显示。所以这是某种自我否定......
回答by berkayk
I am having the same problem after I installed Visual Studio 2012 to evaluate. It seems that normal service and mex service cannot share same port as it used to be in .NET 4.0 with same config file (I dont know why, there must be a reason). Briefly I have my service client references on a different assembly and wpf application on a different assembly. I published mex with different port as this
安装 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>
My service reference assembly config
我的服务参考程序集配置
<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>
Finally my client app config
最后我的客户端应用程序配置
<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>
回答by dugas
I experienced this issue after installing .Net 4.5 and am posting a solution here to help others if they stumble into it. @berkayk's answer above worked (exposing the mex on a different port), but I needed to expose both endpoints through the same port.
我在安装 .Net 4.5 后遇到了这个问题,我在这里发布了一个解决方案,以帮助其他人偶然发现它。@berkayk 上面的回答有效(在不同的端口上公开 mex),但我需要通过同一个端口公开两个端点。
Assume you have two endpoints, one using netTcpBinding and one using mexTcpBinding. When using the default bindings, some of the defaults are calculated using OSEnvironmentHelper.ProcessorCount instead of hard coded values as they were in .Net 4.0.
假设您有两个端点,一个使用 netTcpBinding,一个使用 mexTcpBinding。使用默认绑定时,一些默认值是使用 OSEnvironmentHelper.ProcessorCount 计算的,而不是像在 .Net 4.0 中那样使用硬编码值。
In my case, when using a named netTcpBinding bindingConfiguration, the value supplied for the MaxConnections property was 20. Setting the MaxConnections property on the NetTcpBinding also sets it's TcpTransportBindingElement's MaxPendingConnections property and the TcpTransport's ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint property to the same value.
在我的例子中,当使用命名的 netTcpBinding bindingConfiguration 时,为 MaxConnections 属性提供的值为 20。在 NetTcpBinding 上设置 MaxConnections 属性也会将它的 TcpTransportBindingElement 的 MaxPendingConnections 属性和 TcpTransport 的 ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint 属性设置为相同的值。
When not using a named netTcpBinding bindingConfiguration, and only using the default, the MaxPendingConnections property was calculated by using the following algorithm:
当不使用命名的 netTcpBinding bindingConfiguration 并且仅使用默认值时,MaxPendingConnections 属性是通过使用以下算法计算的:
return (12 * OSEnvironmentHelper.ProcessorCount);
The mexTcpBinding's transport also calculated it's MaxPendingConnections property using the above algorithm, so when neither is using a named bindingConfiguration the default values match and there is no issue.
mexTcpBinding 的传输还使用上述算法计算了它的 MaxPendingConnections 属性,因此当两者都不使用命名 bindingConfiguration 时,默认值匹配并且没有问题。
When using a named netTcpBinding bindingConfiguration, the transport's MaxPendingConnections was 20, and the mexTcpBinding's transport's MaxPendingConnections was, on my machine, 96. The difference in values for the MaxPendingConnections between these two endpoints sharing the same port is incompatible.
使用命名的 netTcpBinding bindingConfiguration 时,传输的 MaxPendingConnections 为 20,而 mexTcpBinding 的传输的 MaxPendingConnections 在我的机器上为 96。共享同一端口的这两个端点之间的 MaxPendingConnections 值的差异是不兼容的。
I also found that this issue occurred with the ListenBacklog set as well. (I do not know of all the possible conflicting values that may exist.)
我还发现这个问题也发生在 ListenBacklog 集上。 (我不知道可能存在的所有可能的冲突值。)
To resolve the issue, you can create a custom binding for mex that matches the named bindingConfiguration for netTcpBinding. Example below:
要解决此问题,您可以为 mex 创建一个与 netTcpBinding 的命名 bindingConfiguration 匹配的自定义绑定。下面的例子:
<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>
Or, you can not specify any values that are calculated (like maxConnections and listenBacklog) and accept the defaults (note that MaxOutboundConnectionsPerEndpoint will still retain the default value of 10 as it is not calculated in the same way that the MaxPendingConnections property is):
或者,您不能指定任何计算值(如 maxConnections 和 listenBacklog)并接受默认值(请注意,MaxOutboundConnectionsPerEndpoint 仍将保留默认值 10,因为它的计算方式与 MaxPendingConnections 属性不同):
<binding name="TestNetTcpBinding" ...someOtherProperties except listenBacklog and maxConnections/>
Note: The issue is described here: http://msdn.microsoft.com/en-us/library/aa702636.aspx, but the only solution given is to expose the mex on a different port. Below are some screenshots in reflector that show the difference between .net 4.0 and 4.5 when calculating the MaxPendingConnections defaults:
注意:这里描述了这个问题:http: //msdn.microsoft.com/en-us/library/aa702636.aspx,但给出的唯一解决方案是在不同的端口上公开 mex。以下是反射器中的一些屏幕截图,显示了计算 MaxPendingConnections 默认值时 .net 4.0 和 4.5 之间的差异:






回答by Ozesh
Well... mine worked when I changed the target framework to .Net framework 4 Client Profile.
嗯...当我将目标框架更改为 .Net framework 4 Client Profile 时,我的工作正常。
Try it out... hope it works for you as well!
试试看……希望它也适合你!

