首页 > 解决方案 > 当 portId = 0 时,TcpServerChannel 抛出 SocketException

问题描述

我有一个 Windows 服务,它在启动时创建一个新的 tcp 通道New TcpServerChannel(0)。通过设置端口 id = 0,它应该动态选择可用的端口 id。但是,我在生产环境中不时遇到以下错误。我无法在本地环境中重现它,这使得调试非常困难。

关于生产环境:

此服务由另一个 Windows 服务定期启动/停止。并且错误只是时有发生,也只有在第一次成功启动后才会发生。当它启动失败时,我去了生产环境,手动启动了这个服务,然后一切都很好。

有什么建议吗?我检查了在生产环境中没有启用互联网共享。

顺便说一句,我怎么知道哪个端口new TcpServerChannel(0)正在尝试分配,因为它直接抛出异常?

System.Net.Sockets.SocketException:试图以一种被系统的 System.Net.Sockets.Socket.DoBind(System.Net.EndPoint, System.Net.SocketAddress) 的访问权限禁止的方式访问套接字。 Net.Sockets.Socket.Bind(System.Net.EndPoint) 在 System.Net.Sockets.TcpListener.Start(Int32) 在 System.Runtime.Remoting.Channels.ExclusiveTcpListener.Start(Boolean)
在 System.Runtime.Remoting.Channels .Tcp.TcpServerChannel.StartListening(System.Object) 在 System.Runtime.Remoting.Channels.Tcp.TcpServerChannel.SetupChannel()
在 System.Runtime.Remoting.Channels.Tcp.TcpServerChannel..ctor(System.Collections.IDictionary, System.Runtime.Remoting.Channels.IServerChannelSinkProvider, System.Runtime.Remoting.Channels.IAuthorizeRemotingConnection) 在 System.Runtime.Remoting.Channels .Tcp.TcpChannel..ctor(System.Collections.IDictionary,System.Runtime.Remoting.Channels.IClientChannelSinkProvider,System.Runtime.Remoting.Channels.IServerChannelSinkProvider)

标签: c#socketstcpremoting

解决方案


推荐阅读