tags:

views:

1494

answers:

3

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.

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

+2  A: 

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

Dave Van den Eynde
It seems...The Service1 has "VitalSigns" server listening at port 9001 and Service2 has "VitalSigns" server listening at port 9002. The Service1 will check vital signs of Service2 and Service 2 will check of Service1If I dont run the server in one instance and check other's it work fine...but I want server/client in each
Khurram Aziz
+1  A: 

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

Stevo3000
The ports are different..
Khurram Aziz
@Khurram Aziz - So each instance opens different ports (rather than each instance opens multiple ports, but uses different ones)?
Stevo3000
@Khurram Aziz - Have you got both channels using different names?
Stevo3000
Specifying name while creating an instance of TcpServerChannel resolved the issued.
Khurram Aziz
+2  A: 

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 = 82131;
        // ------------------------------------------------------------
        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);
Charles Bretana
" int tcpPort = 82131;" WTF. 82131, 65535?
Behrooz