/// <summary> /// Makes a connection to the service's remoting channel. /// </summary> public void Connect() { if (this.isConnected) { return; } try { System.Collections.Hashtable props = new System.Collections.Hashtable(); props["typeFilterLevel"] = "Full"; // Both formatters only use the typeFilterLevel property BinaryClientFormatterSinkProvider cliFormatter = new BinaryClientFormatterSinkProvider(props, null); BinaryServerFormatterSinkProvider srvFormatter = new BinaryServerFormatterSinkProvider(props, null); // The channel requires these to be set that it can found by name by the service props["name"] = "ConsoleClient"; props["portName"] = "ConsoleClient"; props["authorizedGroup"] = "Everyone"; // Create the channel channel = new IpcChannel(props, cliFormatter, srvFormatter); // Register the channel for remoting use System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false); // Create the refence to the service's remoting channel remoter = (ClientMethods)Activator.GetObject(typeof(ClientMethods), "ipc://SyslogConsole/Server"); // Register the MessageReceivedCallback event on the handler RemotingConfiguration.RegisterWellKnownServiceType(typeof(MessageReceivedCallbackSink), "ServerEvents", WellKnownObjectMode.Singleton); // Setup the event subscription sink = new MessageReceivedSink(); remoter.MessageHandled += new MessageReceivedCallback(sink.FireMessageReceived); this.isConnected = true; } catch { this.isConnected = false; } }
/// <summary> /// Raise the message received event for listening clients. /// </summary> /// <param name="e">Event data.</param> private void Listener_MessageReceived(MessageReceivedEventArgs e) { ClientMethods.FireNewMessageReceived(e.SyslogMessage); }