.NET Remoting, How to share MarshalByRefObject interface between BOTH the client and server?

Nov 13, 2012 at 2:46 AM

Solved @ http://stackoverflow.com/questions/13354882/easyhook-net-remoting-sharing-interface-between-both-client-and-server

Nov 20, 2012 at 10:13 AM
Edited Nov 20, 2012 at 10:14 AM

I have just created an issue before I noticed your post about a similar problem.

https://easyhook.codeplex.com/workitem/23638

I used to do n-tier development using .NET remoting in .NET fw 1.1 before eventually switching to Web Services and then to WCF, so in my project the client and the server libraries are separated using a 3rd interface library.

Instead of using MarshalByRefObj's, I use interfaces that are implemented by MarshalByRefObj's, and initialize and consume .NET remoting objects like:

 

// --------------------------------------------------------------------------------
// on the server side
// --------------------------------------------------------------------------------
class ServerAssembly.SomeServer : MarshalByRefObj, SharedAssembly.ISomeServerInterface {
    void DoSomething() {}
}

SomeServer someServer = RemoteHooking.IpcCreateServer<SomeServer>(ref this.ChannelName, WellKnownObjectMode.Singleton);

// --------------------------------------------------------------------------------
// on the client side
// --------------------------------------------------------------------------------
ISomeServerInterface someServerInterface = (ISomeServerInterface)Activator.GetObject(typeof(ISomeServerInterface), "ipc://" + channelName + "/" + channelName);
someServerInterface.DoSomething();