Search code examples
c#.netremotingremote-server

What's the simplest way to connect to a .NET remote server object


Given that my client code knows everything it needs to about the remoting object, what's the simplest way to connect to it?

This is what I'm doing at the moment:

ChannelServices.RegisterChannel(new HttpChannel(), false);

RemotingConfiguration.RegisterWellKnownServiceType(
    typeof(IRemoteServer), "RemoteServer.rem", WellKnownObjectMode.Singleton);

MyServerObject = (IRemoteServer)Activator.GetObject(
    typeof(IRemoteServer),
    String.Format("tcp://{0}:{1}/RemoteServer.rem", server, port));

Solution

  • The first two lines are in the server-side code, for marshaling out the server object, yes?

    In that case, yes, the third line is the simplest you can get at client-side.

    In addition, you can serve out additional server-side objects from the MyServerObject instance, if you include public accessors for them in IRemoteServer interface, so, accessing those objects become the simple matter of method calls or property accesses on your main server object, so you don't have to use activator for every single thing:

    //obtain another marshalbyref object of the type ISessionManager:
    ISessionManager = MyServerObject.GetSessionManager();