【发布时间】:2016-05-23 15:11:24
【问题描述】:
我有零星的问题,并不总是发生。
我有侦听某个端口(.NET Remoting)的 Windows 服务。
这里是注册频道的代码:
void RegisterChannel(int portNumber, string bindTo)
{
ListDictionary channelProperties = new ListDictionary();
channelProperties.Add("name", Guid.NewGuid().ToString().ToUpper());
channelProperties.Add("port", portNumber);
channelProperties.Add("bindTo", bindTo);
channelProperties.Add("secure", true.ToString());
channelProperties.Add("impersonate", true.ToString());
channelProperties.Add("useIpAddress", false.ToString());
BinaryClientFormatterSinkProvider clientFormatter = new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverFormatter = new BinaryServerFormatterSinkProvider();
serverFormatter.TypeFilterLevel = TypeFilterLevel.Full;
TcpChannel tcpChannel = new TcpChannel(channelProperties, clientFormatter, serverFormatter);
ChannelServices.RegisterChannel(tcpChannel, true);
}
RegisterChannel(9000, "[::]");
RegisterChannel(9000, "0.0.0.0");
RemotingConfiguration.RegisterWellKnownServiceType(typeof(AccessServer), "AccessLayer", WellKnownObjectMode.Singleton);
如果我在 Visual Studio 中开始调试此服务然后停止调试,之后我将无法开始调试。
我收到以下异常: 每个套接字地址(协议/网络地址/端口)通常只允许使用一次
运行 netstat –anbo 显示:
TCP 0.0.0.0:9000 0.0.0.0:0 LISTENING 3432 [系统]
TCP [::]:9000 [::]:0 LISTENING 3432 [系统]
之后我必须重新启动,否则端口将永远占用。
有什么解决办法吗?
【问题讨论】:
标签: remoting