频道 'tcp' 已注册

Posted

技术标签:

【中文标题】频道 \'tcp\' 已注册【英文标题】:The channel 'tcp' is already registered频道 'tcp' 已注册 【发布时间】:2010-10-24 18:50:51 【问题描述】:

我希望给定的应用程序(Windows 服务)充当远程服务器和远程客户端。在生产中,我将运行我的应用程序的两个实例,通过 .NET Remoting 相互监控,并相应地报告故障。

我已经写了一个基本的部分,并得到“通道'tcp'已注册”异常..我想以编程方式设置通道配置。

【问题讨论】:

【参考方案1】:

每个AppDomain 只能创建一次具有相同端口号的相同通道。有什么问题吗?

【讨论】:

看来...Service1 的“VitalSigns”服务器在端口 9001 上监听,Service2 的“VitalSigns”服务器在端口 9002 上监听。Service1 将检查 Service2 的生命体征,而 Service 2 将检查Service1 如果我不在一个实例中运行服务器并检查其他实例,它工作正常......但我希望每个实例中都有服务器/客户端【参考方案2】:

正如其他人所说,如果您不指定频道名称,则默认情况下代码使用“tcp”并且每个频道都必须有一个唯一的名称:因此为您打开的每个频道指定一个唯一的名称...

   int tcpPort = 52131;
    // ------------------------------------------------------------
    BinaryServerFormatterSinkProvider serverProv =
        new BinaryServerFormatterSinkProvider();
    serverProv.TypeFilterLevel = TypeFilterLevel.Full; 
    RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;

    serverProv.TypeFilterLevel = TypeFilterLevel.Full;
    IDictionary propBag = new Hashtable();
    // -----------------------------------------
    bool isSecure = [true/false];
    propBag["port"] = tcpPort ;
    propBag["typeFilterLevel"] = TypeFilterLevel.Full;
    propBag["name"] = "UniqueChannelName";  // here enter unique channel name
    if (isSecure)  // if you want remoting comm to be secure and encrypted
    
        propBag["secure"] = isSecure;
        propBag["impersonate"] = false;  // change to true to do impersonation
    
    // -----------------------------------------
    tcpChan = new TcpChannel(
        propBag, null, serverProv);
    ChannelServices.RegisterChannel(tcpChan, isSecure);
    // --------------------------------------------

    string uRI = MyUniversalResourceIndicatorName;
    // ---------------------------------------------

    RemotingConfiguration.RegisterWellKnownServiceType(
        typeof(ImportServiceManager), uRI ,
        WellKnownObjectMode.SingleCall);

【讨论】:

"int tcpPort = 82131;"哇。 82131, 65535?【参考方案3】:

具有特定端口号的通道只能由一个应用程序实例创建。您需要为每个实例使用不同的端口号和通道名称。

这需要使用单独的频道模板(如果您正在使用模板?)。

【讨论】:

@Khurram Aziz - 所以每个实例打开不同的端口(而不是每个实例打开多个端口,但使用不同的端口)? @Khurram Aziz - 你有两个频道使用不同的名字吗? 在创建 TcpServerChannel 实例时指定名称解决了问题。

以上是关于频道 'tcp' 已注册的主要内容,如果未能解决你的问题,请参考以下文章

向 mio 注册频道

一个频道的多个推送注册

使用 Azure 通知中心 REST API 读取频道的所有注册

Azure 机器人频道注册如何对我的团队应用进行身份验证

Microsoft bot 框架 - Bot 频道注册。无法将录制的视频从 Skype 保存到 Azure 存储帐户

大量 Win11 内测用户被困在 Dev 开发频道中,修改注册表都没用