Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
518 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...