c# - 当 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)
解决方案
推荐阅读
- bash - Bash:获取打印函数的状态
- javascript - How to display an array of pair arrays as key values pairs?
- deployment - 我如何知道谷歌云何时完成部署我的网站?
- robotframework - 如何在控制台错误时停止机器人框架套件的执行?
- android - android联系人中的is_primary标志何时设置为非零值?
- c# - 母版页不会在 Web 窗体上显示其内容
- vue.js - Vue.js 和 VueRouter 性能缓慢
- spring-boot - 如果@Scheduled 注解的方法在两台不同的机器上运行,它会被调用两次吗?
- sql - json字段上的PosgtreSQL连接表
- mongodb - 日期标准不适用于使用spring数据的mongodb