Get remote object and respond to an event
-
I'm currently trying to get a remote object, using Remoting... I can get the object, but I can't grab a event the object fires. This is all example code and I just can't seem to get it work. I get the object, but the remote object doesn't see the client sign up to watch for the event, so it never fires the event. Or if you have a better way for my Server and Client to communicate, don't hesitate to share. Any help with would greatly appreciated. If you have more questions, please email me. [Server] using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace Test.Remote { /// /// Summary description for Class1. /// class Server { static void Main(string[] args) { TcpServerChannel channel = new TcpServerChannel(8086); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "Hi", WellKnownObjectMode.SingleCall); Console.WriteLine("Hit to exit"); Console.ReadLine(); } } } [Client] using System; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; namespace Test.Remote { /// /// Summary description for Class1. /// class Client { [STAThread] static void Main(string[] args) { //RemotingConfiguration.Configure("Client.exe.config"); ChannelServices.RegisterChannel(new TcpClientChannel()); RemoteObject obj = (RemoteObject)Activator.GetObject(typeof(RemoteObject), "tcp://localhost:8086/Hi"); EventSink sink = new EventSink(); // register client sink in server - subscribe to event obj.Status += new StatusEvent(sink.StatusHandler); obj.LongWorking(5000); // unsubscribe to event obj.Status -= new StatusEvent(sink.StatusHandler); obj.LongWorking(5000); Console.WriteLine("Hit to exit"); Console.ReadLine(); } } } [RemoteObject] using System; namespace Test.Remote { [Serializable] public class StatusEventArgs { public StatusEventArgs(string m) { message = m; } public string Message { get { return message; } set { message = value; } } private string message; } public delegate void StatusEvent(object sender, StatusEventArgs e); /// /// Summary description for Class1. /// public class RemoteObject : MarshalByRefObject { public RemoteObject() { Console.WriteLine("RemoteObject constructor called"); } public event StatusEvent Status; public void LongWorking(int ms) { Console.W