简体   繁体   English

频道'tcp'已经注册

[英]The channel 'tcp' is already registered

I want the given application (Windows Service) to act as a remoting server as well as remoting client. 我希望给定的应用程序(Windows服务)充当远程服务器以及远程客户端。 In production I will run the two instances of my application monitoring each other over .NET Remoting and will report the failures accordingly. 在生产中,我将运行我的应用程序的两个实例,通过.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'“例外..我想以编程方式设置通道配置。

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);

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?). 这需要使用单独的通道模板(如果您使用的是模板?)。

You can only create the same channel with the same portnumber once per AppDomain . 每个AppDomain只能创建一个具有相同portnumber的相同通道。 Is that what's wrong? 这有什么不对吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM