C# 通道 'tcp' 已经注册

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/839577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 03:37:07  来源:igfitidea点击:

The channel 'tcp' is already registered

c#remoting

提问by Khurram Aziz

I want the given application (Windows Service) to act as a remoting server as well as remoting client. In production I will run the two instances of my application monitoring each other over .NET Remoting and will report the failures accordingly.

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

I have written a basic pieces, and getting "The channel 'tcp' is already registered" exception..I want to set the channel configuration programmatically.

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

采纳答案by stevehipwell

A channel with a specific port number can only be created by one application instance. You need to use different port numbers and channel names for each instance.

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

This requires using seperate channel templates (if you are using templates?).

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

回答by Dave Van den Eynde

You can only create the same channel with the same portnumber once per AppDomain. Is that what's wrong?

每次只能创建具有相同端口号的相同通道一次AppDomain。这是怎么回事?

回答by Charles Bretana

As others have said, if you don't specify the channel name, the code by default uses "tcp" and every channel has to have a unique name: So specify a unique name for each channel you open...

正如其他人所说,如果您不指定频道名称,默认情况下代码使用“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);