【问题标题】:Exception in the Socket#33711845::DoBind - Only one usage of each socket address (protocol/network address/port) is normally permittedSocket#33711845::DoBind 中的异常 - 每个套接字地址(协议/网络地址/端口)通常只允许使用一次
【发布时间】:2010-03-15 06:14:57
【问题描述】:

我正在尝试设置一个简单的远程 Windows 服务,并在启动服务时收到以下错误:

System.Net.Sockets Error: 0 : [4180] Exception in the Socket#33711845::DoBind - Only one usage of each socket address (protocol/network address/port) is normally permitted
System.Net.Sockets Verbose: 0 : [4180] ExclusiveTcpListener#4032828::Start()
System.Net.Sockets Verbose: 0 : [4180] Socket#33711845::Bind(0:9998#9998)
System.Net.Sockets Error: 0 : [4180] Exception in the Socket#33711845::DoBind - Only one usage of each socket address (protocol/network address/port) is normally permitted

在 Windows 服务应用程序中,我在“OnStart”方法中有以下代码 - 注册频道时发生错误 - ChannelServices.RegisterChannel(tcpPipe, true);据我所知,没有其他进程使用端口 9998 ...

   protected override void OnStart(string[] args)
    {

        int portNumber = int.Parse(ConfigurationManager.AppSettings["endPointTCPPort"]);

        TcpChannel tcpPipe = new TcpChannel(portNumber);

        ChannelServices.RegisterChannel(tcpPipe, true);

        Type serviceType = Type.GetType("TractionGatewayService.TractionGateway");

        try
        {
           RemotingConfiguration.RegisterWellKnownServiceType(serviceType, "updateCustomerDetails", WellKnownObjectMode.SingleCall);
        }
        catch (RemotingException e)
        {
            EventLog.WriteEntry("unable to establish listening port because " + e.message; 
            ChannelServices.UnregisterChannel(tcpPipe);
        }

【问题讨论】:

  • 我偶尔会在 Windows 服务中遇到完全相同的问题。尝试运行 netstat -b 并检查哪个进程拥有您的端口以及它处于哪个状态?就我而言,SYSTEM 是端口状态为“ESTABLISHED”的所有者,解决方法是重新启动系统。
  • 嗨,达格,感谢您的回复。我已经运行了 netstat,但没有提及我尝试使用的端口 - 9998。在创建“Windows 服务”之前,我编写了这段代码以在控制台窗口下运行。我可以使用端口 9998 运行控制台代码而没有任何问题 - 我只有在 Windows 服务下运行上述代码时才会收到此错误。我可能应该提到我已经在我的工作站上安装了这个服务。
  • 很高兴您发现了问题。为了其他阅读本文的人的利益,我将指出 .NET Remoting 现在已弃用,取而代之的是 WCF。

标签: .net .net-remoting


【解决方案1】:

我发现了问题。我对 TcpChannel 进行了两次单独的调用来注册端口 - 因此出现了错误。
感谢所有看过这个的人。
...

【讨论】:

    猜你喜欢
    • 2019-05-03
    • 2017-06-09
    • 2011-01-15
    • 1970-01-01
    • 2010-11-23
    相关资源
    最近更新 更多