Example #1
0
        /// <summary>
        /// Safely register the TcpChannel for this service.
        /// </summary>
        /// <param name="port">The port on which the service will listen.</param>
        /// <returns>true if registration succeeded; false, otherwise.</returns>
        public static bool RegisterService(int port)
        {
            try
            {
                if (s_ChordTcpChannel != null)
                {
                    ChordServer.UnregisterService();
                }

                BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
                provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

                IDictionary props = new Hashtable();
                props["port"] = port;

                s_ChordTcpChannel = new TcpChannel(props, null, provider);

                ChannelServices.RegisterChannel(s_ChordTcpChannel, false);
                RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChordInstance), "chord", WellKnownObjectMode.Singleton);
            }
            catch (Exception e)
            {
                ChordServer.Log(LogLevel.Error, "Configuration", "Unable to register Chord Service ({0}).", e.Message);
                return(false);
            }

            ChordServer.Log(LogLevel.Info, "Configuration", "Chord Service registered on port {0}.", port);

            return(true);
        }