[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Singleton problem under IIS

Keith Foster

7/8/2004 10:35:00 AM

Hi,

I have a remote object (residing in a DLL) that is hosted by IIS. The
object should be created as a singleton as specified in the web.config :

<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="Singleton" type="myNamespace.myObj, myObj"
objectUri="myObj.soap" />
</service>
</application>
</system.runtime.remoting>
</configuration>

This is read by IIS and used to fire up my object?

The code within the object is shown below. Basically i need a singleton
object (myObj ) that then creates remote instances of the BL object for
individual clients to use. In the code, for each new client that requests a
BL object, the s_objNumber member should be incremented.. However
ObjNumber always returns 1 to the client.

Any ideas as to why this is happening? I suspect that I'm doing something
stupid but can't quite see it : )

Is this the way I should approach the problem anyway?

Thanks for any help on this problem.

public class BL : MarshalByRefObject
{
static private int s_objNumber = 0;
private int m_objNumber = 0;
public BL()
{
m_objNumber = ++s_objNumber;
}
public int ObjNumber
{
get{ return m_objNumber; }
}
}
public class myObj : MarshalByRefObject
{
public myObj()
{
}
public int Connect()
{
return 1;
}
static public BL CreateBusinessLayerObject()
{
return new BL();
}

public override object InitializeLifetimeService()
{
return null;
}
}


7 Answers

Sunny

7/8/2004 2:47:00 PM

0

It seems that this is not the problem, buy your code is not thread safe
(at least the incremet of the counter).

Also, I''d change the code like this:


In article <ccj803$23k$1@thorium.cix.co.uk>, Keith.Foster@XXXsirius-
analytical.com says...
<snip>

> public class BL : MarshalByRefObject
> {
> private int m_objNumber = 0;
public BL(int nr)
> {
m_objNumber = nr;
> }
> public int ObjNumber
> {
> get{ return m_objNumber; }
> }
> }
> public class myObj : MarshalByRefObject
> {
private int cnt;
> public myObj()
> {
this.cnt = 0;
> }
> public int Connect()
> {
> return 1;
> }
//this method does not have to be static. The singleton object will
expose it to all clients.

public BL CreateBusinessLayerObject()
> {
//using Interlocked class helps to avoid any threading issues
return new BL(System.Threading.Interlocked.Increment(ref
this.cnt));
> }
>
> public override object InitializeLifetimeService()
> {
> return null;
> }
> }
>
>
>


Please see if it helps.

I do not have time now to test your example but it seems very unusual.

Sunny

Ken Kolda

7/8/2004 2:53:00 PM

0

I''m actually surprised you''re always getting 1 -- that part of the code
looks OK (except for the fact it''s not thread-safe -- see
Interlocked.Increment() to fix that). The real problem is that you''re
actually creating your BL objects on the client, not on the server. The
reason is that you''ve declared the CreateBusinessLayerObject() as static
instead of as an instance method. Static methods are never remoted, they''re
always called in the same AppDomain as the caller (after all, it''s the
instances of the class which are remote, not the class itself).

Ken


"Keith Foster" <Keith.Foster@XXXsirius-analytical.com> wrote in message
news:ccj803$23k$1@thorium.cix.co.uk...
> Hi,
>
> I have a remote object (residing in a DLL) that is hosted by IIS. The
> object should be created as a singleton as specified in the web.config :
>
> <configuration>
> <system.runtime.remoting>
> <application>
> <service>
> <wellknown mode="Singleton" type="myNamespace.myObj,
myObj"
> objectUri="myObj.soap" />
> </service>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> This is read by IIS and used to fire up my object?
>
> The code within the object is shown below. Basically i need a singleton
> object (myObj ) that then creates remote instances of the BL object for
> individual clients to use. In the code, for each new client that requests
a
> BL object, the s_objNumber member should be incremented.. However
> ObjNumber always returns 1 to the client.
>
> Any ideas as to why this is happening? I suspect that I''m doing something
> stupid but can''t quite see it : )
>
> Is this the way I should approach the problem anyway?
>
> Thanks for any help on this problem.
>
> public class BL : MarshalByRefObject
> {
> static private int s_objNumber = 0;
> private int m_objNumber = 0;
> public BL()
> {
> m_objNumber = ++s_objNumber;
> }
> public int ObjNumber
> {
> get{ return m_objNumber; }
> }
> }
> public class myObj : MarshalByRefObject
> {
> public myObj()
> {
> }
> public int Connect()
> {
> return 1;
> }
> static public BL CreateBusinessLayerObject()
> {
> return new BL();
> }
>
> public override object InitializeLifetimeService()
> {
> return null;
> }
> }
>
>


Keith Foster

7/8/2004 4:56:00 PM

0

Thanks for the replies .. I think I was getting in a bit of a mess with that
(it was quite early in the morning).

The thing I''m trying to do is:

1. Implement a singleton server (running as an exe) which exposes some
remotable objects.
2. Call these objects remotely from several concurrent clients.
3. Keep some means within the server of knowing which clients are actually
connected. The clients will be required to first log on and thereafter all
subsequent calls by the client need to be checked to establish whether or
not a log on has been successful. Essentially I am trying to recreate what
Session[""] does for you in a WebService.

I thought that I could use a [ThreadStatic] variable to hold a username, for
example, for each connected client - this is not working - the variable is
the same for all clients.

Is there a ''established'' means of mimicking the Session[""] object in a
non-webservice? Could I use the HttpCallContext or something?

Again thanks for any help with this.





"Keith Foster" <Keith.Foster@XXXsirius-analytical.com> wrote in message
news:ccj803$23k$1@thorium.cix.co.uk...
> Hi,
>
> I have a remote object (residing in a DLL) that is hosted by IIS. The
> object should be created as a singleton as specified in the web.config :
>
> <configuration>
> <system.runtime.remoting>
> <application>
> <service>
> <wellknown mode="Singleton" type="myNamespace.myObj,
myObj"
> objectUri="myObj.soap" />
> </service>
> </application>
> </system.runtime.remoting>
> </configuration>
>
> This is read by IIS and used to fire up my object?
>
> The code within the object is shown below. Basically i need a singleton
> object (myObj ) that then creates remote instances of the BL object for
> individual clients to use. In the code, for each new client that requests
a
> BL object, the s_objNumber member should be incremented.. However
> ObjNumber always returns 1 to the client.
>
> Any ideas as to why this is happening? I suspect that I''m doing something
> stupid but can''t quite see it : )
>
> Is this the way I should approach the problem anyway?
>
> Thanks for any help on this problem.
>
> public class BL : MarshalByRefObject
> {
> static private int s_objNumber = 0;
> private int m_objNumber = 0;
> public BL()
> {
> m_objNumber = ++s_objNumber;
> }
> public int ObjNumber
> {
> get{ return m_objNumber; }
> }
> }
> public class myObj : MarshalByRefObject
> {
> public myObj()
> {
> }
> public int Connect()
> {
> return 1;
> }
> static public BL CreateBusinessLayerObject()
> {
> return new BL();
> }
>
> public override object InitializeLifetimeService()
> {
> return null;
> }
> }
>
>


Ken Kolda

7/9/2004 4:03:00 PM

0

You can''t use any method which is tied to the current thread or current call
context -- after all, you want this session information to be avaiable to
you across remoting calls (which may be executed on different threads). One
way to establish a session is as follows:

1) Provide a SAO singleton (or single-call) with a Login() method. If login
is successful, return to the client a new instance of a CAO, we''ll call it a
"Session" object.

2) All subsequent calls to the server from the client are performed through
this session object -- it essentially acts as the context for the method
call and can store the user''s login credentials and any other state you
need.

Hope that helps -
Ken


"Keith Foster" <Keith.Foster@XXXsirius-analytical.com> wrote in message
news:ccjub1$bpr$1@thorium.cix.co.uk...
> Thanks for the replies .. I think I was getting in a bit of a mess with
that
> (it was quite early in the morning).
>
> The thing I''m trying to do is:
>
> 1. Implement a singleton server (running as an exe) which exposes some
> remotable objects.
> 2. Call these objects remotely from several concurrent clients.
> 3. Keep some means within the server of knowing which clients are
actually
> connected. The clients will be required to first log on and thereafter
all
> subsequent calls by the client need to be checked to establish whether or
> not a log on has been successful. Essentially I am trying to recreate
what
> Session[""] does for you in a WebService.
>
> I thought that I could use a [ThreadStatic] variable to hold a username,
for
> example, for each connected client - this is not working - the variable
is
> the same for all clients.
>
> Is there a ''established'' means of mimicking the Session[""] object in a
> non-webservice? Could I use the HttpCallContext or something?
>
> Again thanks for any help with this.
>
>
>
>
>
> "Keith Foster" <Keith.Foster@XXXsirius-analytical.com> wrote in message
> news:ccj803$23k$1@thorium.cix.co.uk...
> > Hi,
> >
> > I have a remote object (residing in a DLL) that is hosted by IIS. The
> > object should be created as a singleton as specified in the web.config :
> >
> > <configuration>
> > <system.runtime.remoting>
> > <application>
> > <service>
> > <wellknown mode="Singleton" type="myNamespace.myObj,
> myObj"
> > objectUri="myObj.soap" />
> > </service>
> > </application>
> > </system.runtime.remoting>
> > </configuration>
> >
> > This is read by IIS and used to fire up my object?
> >
> > The code within the object is shown below. Basically i need a singleton
> > object (myObj ) that then creates remote instances of the BL object for
> > individual clients to use. In the code, for each new client that
requests
> a
> > BL object, the s_objNumber member should be incremented.. However
> > ObjNumber always returns 1 to the client.
> >
> > Any ideas as to why this is happening? I suspect that I''m doing
something
> > stupid but can''t quite see it : )
> >
> > Is this the way I should approach the problem anyway?
> >
> > Thanks for any help on this problem.
> >
> > public class BL : MarshalByRefObject
> > {
> > static private int s_objNumber = 0;
> > private int m_objNumber = 0;
> > public BL()
> > {
> > m_objNumber = ++s_objNumber;
> > }
> > public int ObjNumber
> > {
> > get{ return m_objNumber; }
> > }
> > }
> > public class myObj : MarshalByRefObject
> > {
> > public myObj()
> > {
> > }
> > public int Connect()
> > {
> > return 1;
> > }
> > static public BL CreateBusinessLayerObject()
> > {
> > return new BL();
> > }
> >
> > public override object InitializeLifetimeService()
> > {
> > return null;
> > }
> > }
> >
> >
>
>


William Sommerwerck

4/8/2010 9:09:00 PM

0

>> The recent Naxos Blu-ray set of Haydn keyboard music
>> includes clavichord performances. Note that it can be
>> played only on a Blu-ray player.

> Won't help me (yet). Seems odd that such a performance
> would be available only on Blu-ray, and not CD or DVD.

It's the cheapest way to provide a "high-resolution" recording running over
15 hours. SACDs would require perhaps a dozen disks.


>> Don't overlook this album...
>> http://www.amazon.com/Porgy-Bess-Oscar-Peterson-Pass/dp/B00......

> Thanks, that's something I must have!


Kip Williams

4/8/2010 9:20:00 PM

0

William Sommerwerck wrote:
>> Given that the original title is an oxymoron, I'm wondering
>> if there are any good *clavichord* recordings -- for both
>> performance and recording merits -- that I should look into.
>
> The recent Naxos Blu-ray set of Haydn keyboard music includes clavichord
> performances. Note that it can be played only on a Blu-ray player.
>
> Don't overlook this album...
>
> http://www.amazon.com/Porgy-Bess-Oscar-Peterson-Pass/dp/B000000Z0M/ref=sr_1_1?ie=UTF8&s=music&qid=1270750332&...

Heh! That's the first thing that came to my mind.

I do have some classical clavichord recordings, but have no strong
opinions on them, pro or con.

Similarly, I thought of mentioning Don Angle's pop harpsichord albums,
of which I have one. For a non-pedaled two-hands performer, he manages
to fill the space up with music very neatly.


Kip W

Terry

4/8/2010 11:17:00 PM

0

On Fri, 9 Apr 2010 03:07:36 +1000, Kevin N wrote
(in article
<9269f68a-2717-41f8-9164-b176362e829b@i25g2000yqm.googlegroups.com>):

> On Apr 5, 9:33?pm, beingveryanonym...@yahoo.co.uk wrote:
>> I've recently upgraded my stereo setup and now find harpsichord
>> recordings really rather pleasant to listen to. I'd like to solicit
>> recommendations for both well-played and well-recorded harpsichord
>> CDs. I really like Parmentier's Bach, Rousset's Couperin, and the INA
>> Scott Ross recital for example.
>>
>> Victor
>
> Given that the original title is an oxymoron, I'm wondering if there
> are any good *clavichord* recordings - for both performance and
> recording merits - that I should look into.

You might try to seek out a CD on the JMS label, in which Thurston Dart plays
music of Froberger, Croft and (of course) Anon. The recording quality is
adequate, quite faithful, (Dart died about 40 years ago), and it's a very
nice recital.

--
Cheers!

Terry