I am trying to use .NET remoting technique to implement a cache type of
object, ie, multiple clients access this cache object which has the client
specific information stored. My server config file is like this:
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" type="MyConns, HFCache"
objectUri="HFCache.MyConns" />
</service>
<channels>
<channel port="8001" ref="tcp" />
</channels>
<lifetime leaseTime="10M" renewOnCallTime="5M" />
</application>
</system.runtime.remoting>
</configuration>
Client side config file:
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellKnown type="MyConns, HFCache"
url="tcp://localhost:8001/HFCache.MyConns" />
</client>
<channels>
<channel ref="tcp" />
</channels>
</application>
</system.runtime.remoting>
</configuration>
In the client code:
MyConns conn = new MyConns();
The a new instance of MyConns is created. (In my MyConns constructor, I
write to EventLog, I saw there more than one entries in EventLog, saying the
MyConns object is created)
I couldn't see where it might went wrong. Please help, really appreciate,
Thank you,
todd.mancini@gmail.com - 17 Dec 2004 22:31 GMT
Do you have more than one instance of MyConns at the same time? A
Singleton just ensures that there will only be one instance at any
given time, but it is possible for the instance to expire, and then,
when needed, a new singleton instance to be created. So, even with
Singletons, unless you control the lease to never expire, the
constructor CAN be called more than once if an instance expires.
Ken Kolda - 17 Dec 2004 22:57 GMT
My guess is that you're not actually instantiating the object on the
server -- you're creating local instances. I see that you have the word
"wellKnown" miscapitalized in your client's config file, so that may be the
first issue (assuming it's accurately transcribed).
To verify you're getting a remote object instead of a local instance, call
RemotingServices.IsTransparentProxy() on the instance of your remote object,
e.g.
MyConn conn = new MyConn();
Debug.Assert(RemotingServices.IsTransparentProxy(conn));
If the assertion fails, you've created a local instance, which explains why
you're getting multiple instance created.
As second possibility (although I doubt this based on your description) is
that the lifetime of the remote object is expiring. If your two method calls
are separated by more than 5 minutes, the object may have been disconnected
and a new instance would be created to service requests. If you want to
ensure on a single MyConn instance is created, be sure to return null from
InitializeLifetimeService().
Ken
> I am trying to use .NET remoting technique to implement a cache type of
> object, ie, multiple clients access this cache object which has the client
[quoted text clipped - 41 lines]
> I couldn't see where it might went wrong. Please help, really appreciate,
> Thank you,