Ejemplo n.º 1
0
        public static void ActivateApi()
        {
            log.Info("Activating API");

            var serverSinkProvider = new BinaryServerFormatterSinkProvider
            {
                TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full
            };

            IDictionary properties = new Hashtable();
            properties["portName"] = System.Configuration.ConfigurationManager.AppSettings["ApiPort"] ?? "localhost:19888";
            properties["authorizedGroup"] = System.Configuration.ConfigurationManager.AppSettings["ApiAccessGroup"] ?? "Interactive";

            var serverChannel = new IpcChannel(properties, null, serverSinkProvider);
            ChannelServices.RegisterChannel(serverChannel,true);

            log.DebugFormat(" - The name of the channel is {0}.",serverChannel.ChannelName);
            log.DebugFormat(" - The priority of the channel is {0}.", serverChannel.ChannelPriority);

            var channelData = (ChannelDataStore)serverChannel.ChannelData;

            foreach (var uri in channelData.ChannelUris)
            {
                log.DebugFormat(" - The channel URI is {0}.", uri);
            }

            RemotingConfiguration.RegisterWellKnownServiceType(
                        typeof(API),"API",WellKnownObjectMode.Singleton
                    );

            var urls = serverChannel.GetUrlsForUri("API");
            if (urls.Length > 0)
            {
                string objectUrl = urls[0];
                string objectUri;
                string channelUri = serverChannel.Parse(objectUrl, out objectUri);
                log.DebugFormat("The object URI is {0}.", objectUri);
                log.DebugFormat("The channel URI is {0}.", channelUri);
                log.DebugFormat("The object URL is {0}.", objectUrl);
            }
        }