I'm having a bit of a problem with a singleton class I'm exposing via remoting. In my server I have:
TcpChannel channel = new TcpChannel( Settings.Default.RemotingPort );
ChannelServices.RegisterChannel( channel, false );
RemotingConfiguration.RegisterWellKnownServiceType(
typeof( RemotableObject ), "RemotableObject",
WellKnownObjectMode.Singleton );
RemotableObject is a singleton object that inherits MarshalByRefObject.
My client connects to it via:
remoteObject = (RemotableObject)Activator.GetObject(
typeof( RemotableObject ),
string.Format( "tcp://{0}:{1}/RemotableObject", serverIP, serverPort ) );
Everything works great as far as the remoting goes, but when I access the singleton object in my server code like this:
int someValue = RemotableObject.Instance.SomeDynamicValue;
It accesses a different instance than the clients do. I have also verified that the private constructor in RemotableObject gets hit twice while debugging.
I can get the desired behavior if I get an instance to RemotableObject via remoting in my server code, but is there a way that I can access the same object as my clients from the server without the remoting overhead?