The channel 'tcp' is already registered

后端 未结 3 476
猫巷女王i
猫巷女王i 2020-12-17 19:42

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 monitorin

相关标签:
3条回答
  • 2020-12-17 20:25

    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...

       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);
    
    0 讨论(0)
  • 2020-12-17 20:29

    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?).

    0 讨论(0)
  • 2020-12-17 20:33

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

    0 讨论(0)
提交回复
热议问题