C# – .NET Remoting – How to the Server update the client

Architectureasynchronouscnetremoting

Right now, I am in prototyping phase. So I am just getting started.

Situation:
Server – Will be run tests and publish progress to Client, must be low impact, no webserver, possibly running xp embedded or xp home.

Client – Initiate tests and receive progress report. running xp pro.

The two machines are connected via ethernet. I would like to use .NET remoting to communicate between the two machines, and I would like to use events to update the client with new results from the server, but I've read that events are unreliable in these conditions. How should I do this? Could the Server connect to the client and use remoting to publish the events? Would that work okay?

Best Answer

I once deployed a system wich used remoting, and where the server launched some events to which the client could subscribe to.

In order to make it possible, you have to set the typeFilterLevel to full, and, you also have to create an 'intermediate' object that is known on the client and on the server in order to be able to handle your events.

For instance: This is the class that is known on the server & on the client side.

public abstract class MyDelegateObject : MarshalByRefObject
{
   public void EventHandlerCallback( object sender, EventArgs e )
   {
      EventHandlerCallbackCore(sender, e);
   }

   protected abstract void EventHandlerCallbackCore(object sender, EventArgs e );

   public override object InitializeLifetimeService() { return null; }
}

At the client-side, you create another class which inherits from the above class, and implements the actual logic that must be performed when the event is raised.

public class MyConcreteHandler : MyDelegateObject
{
   protected override EventHandlerCallbackCore(object sender, EventArgs e)
   {
       // do some stuff
   }
}

You simply attach the eventhandler to the event of the remote object like this:

MyConcreteHandler handler = new MyConcreteHandler();
myRemoteObject.MyEventOccured += new EventHandler(handler.EventHandlerCallback);

Offcourse, if you update Winform controls in your EventHandler class, that class should also implement ISynchronizeInvoke.