Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Remoting / December 2004

Tip: Looking for answers? Try searching our database.

Singleton object is still create multiple instances

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AY - 17 Dec 2004 22:20 GMT
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,

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.