【问题标题】:There is already a listener on IP endpoint 0.0.0.0:13000. ?? (TCP using WCF)IP 端点 0.0.0.0:13000 上已经有一个侦听器。 ?? (使用 WCF 的 TCP)
【发布时间】:2012-03-16 21:21:34
【问题描述】:

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

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

【问题讨论】:

  • 防火墙不应该给你一个 AddressAlreadyInUseException。
  • 我也遇到了这个问题。我已经尝试更改端口,但没有任何效果。
  • 看起来这个 Q 已经过时了。你解决了这个问题了吗?

标签: c# .net windows wcf tcp


【解决方案1】:

我在安装 .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 值的差异是不兼容的。

我还发现 ListenBacklog 集也出现了这个问题。 (我不知道所有可能存在的冲突值。)

要解决此问题,您可以为 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>

或者,您不能指定任何计算的值(如 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 之间的区别:

【讨论】:

  • 你是救生员!花了 2 天的时间,但无法让它工作。刚刚从binding 标签中删除了listenBacklogmaxConnections,它现在可以正常工作了!谢谢一百万!
  • 很好的解释和答案。我知道这是一个问题,但从未理解其背后的原因。谢谢你:)
【解决方案2】:

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

【讨论】:

  • 为我工作。谢谢
【解决方案3】:

您确定您的服务是唯一监听 13000 端口的服务吗?

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

然后运行tasklist | find "&lt;pid&gt;",其中是上一个命令中进程的ID。这会告诉你哪个进程打开了 13000。

【讨论】:

    【解决方案4】:

    netsat -anb(需要管理员权限)会告诉您正在侦听所有端口的内容...如果没有显示任何内容,您可能有一个错误,即您尝试多次创建端点。

    【讨论】:

    • 然后设置 VS studio 中断所有异常,当你看到使用异常的地址时重新运行命令。
    【解决方案5】:

    您是否安装了 .Net Framework 4.5 测试版?我在 4.5 的机器上运行时看到了同样的错误,而它在 4.0 上完美运行。但是,如果我删除 mex 端点,它会再次起作用。

    在我的情况下,4.5 更改中的某些内容导致了相同的错误消息。也许创建了一个自动 mex 端点或其他东西。

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

    【讨论】:

    • 现在我遇到了这个问题,你找到解决办法了吗?
    • 仅删除 app.config 中的元数据端点配置有帮助。
    • 我在 .net 4.5 中遇到了问题 - 请参阅我在此线程中的帖子以获取解决方案。
    【解决方案6】:

    嗯...当我将目标框架更改为 .Net 框架 4 客户端配置文件时,我的工作正常。

    试试吧...希望它也适合你!

    【讨论】:

      猜你喜欢
      • 2020-08-25
      • 2021-12-22
      • 1970-01-01
      • 2015-11-05
      • 2021-02-09
      • 2016-12-30
      • 2012-08-30
      • 1970-01-01
      • 2021-10-21
      相关资源
      最近更新 更多