IP端点0.0.0.0:13000上已有一个侦听器.?? (TCP使用WCF)

LB.*_*LB. 17 .net c# windows wcf tcp

我试图弄清楚为什么即使在重新启动计算机后仍在使用端口!

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

dug*_*gas 29

我在安装.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);
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

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

<binding name="TestNetTcpBinding" ...someOtherProperties except listenBacklog and maxConnections/>
Run Code Online (Sandbox Code Playgroud)

注意:此处描述了该问题: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方法

  • 你是一个救生员!在这上花了2天但却无法上班.刚刚从`binding`标签中删除了`listenBacklog`和`maxConnections`,现在工作正常!谢谢你! (5认同)

小智 14

安装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>
Run Code Online (Sandbox Code Playgroud)

我的服务引用程序集配置

<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>
Run Code Online (Sandbox Code Playgroud)

最后我的客户端应用配置

    <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>
Run Code Online (Sandbox Code Playgroud)


vil*_*der 6

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

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

然后运行tasklist | find "<pid>"上一个命令中进程的ID.这将告诉您哪个进程有13000打开.


Yau*_*aur 4

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