By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,948 Members | 1,545 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,948 IT Pros & Developers. It's quick & easy.

Singleton on server

P: n/a
I hope, I misunderstood some basics here and it is easy to solve..
I need a singleton object running on server which can be used(write
and read) by different client interfaces - for example there is
webservice that simply transfer calls to this object and there is a
COM Interop, that does the same. Also I need to control lifecycle and
behaviour of this singleton - and for that I am going to have window
application, that will start and finish it.
I do not have problem with the last part :) - I run window app and
request an instance of my singleton. But how can I make another apps
(webservice and COM interop) to work with the same singleton? I
believe it is doable, but how?

Feb 15 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On Feb 15, 2:58 pm, oleg...@gmail.com wrote:
I hope, I misunderstood some basics here and it is easy to solve..
I need a singleton object running on server which can be used(write
and read) by different client interfaces - for example there is
webservice that simply transfer calls to this object and there is a
COM Interop, that does the same. Also I need to control lifecycle and
behaviour of this singleton - and for that I am going to have window
application, that will start and finish it.
I do not have problem with the last part :) - I run window app and
request an instance of my singleton. But how can I make another apps
(webservice and COM interop) to work with the same singleton? I
believe it is doable, but how?
I think reading up on Singleton might answer your question:

http://en.wikipedia.org/wiki/Singleton_pattern

Scroll down in this article, find C# generics.

Just curious, have you also go as Olegik on fool.com?

Quoc Linh

Feb 15 '07 #2

P: n/a
I think I have some understanding of how singleton works. WHat I do
not understand is how to make it singleton systemwise, not only
processwise(or appdomain wise if you wish). I created a singleton
instance in my window app, but now how webservice can read/write to
it?
The closest thing to what I want is Singleton model in NET Remoting,
but because ther will be no remote direct connections to this object
( only through web service or pure SOAP), there is no reason to do
Remoting.

PS. No, I am not Olegik from fool.com.
I think reading up onSingletonmight answer your question:

http://en.wikipedia.org/wiki/Singleton_pattern

Scroll down in this article, findC#generics.

Just curious, have you also go as Olegik on fool.com?

Quoc Linh

Feb 16 '07 #3

P: n/a
(disclaimer: not a solution)
Can I quickly question *why* you want a system-wide singleton with
read/write on a web-server? In most cases, this is a bag call: the
write access forces you to make the class thread-safe, which means
that you are serializing all web-requests. This is not a good thing in
terms of scalability. Usually when I see this, the correct answer is
to use a database to handle the centralised access to common data (in
a controlled manner).

One other issue with the above approach is that it also doesn't scale
out if the idea is to have a single version of the truth; in a
cluster, you start having to remote between them to a single throttle-
point (singleton). Database servers are more geared-up to do this job.

Anyway; your scenario could be different, and it might be a good
idea... but worth challenging ;-p

Marc

Feb 16 '07 #4

P: n/a
This will require some form of remoting to marshal between processes. The
first two that come directly to mind is Remoting and WCF. Based on the
limited info I gleen from post, I might create a .Net service that hosts the
singleton. Then use remoting to surface the MBR singleton object as it is
easy and fast (other ipc options could be namedpipes, memmappedfile,
sockets, etc). All your other apps then become clients of the service.
Your win management app becomes a remoting client, your web service becomes
a remoting client, a console mgmt app becomes a remoting client, your com
app becomes a remoting app - they all acess the same library the same way
with the same MBR proxy api. Pretty clean solution imo (you could use WCF
in same kinda way). You don't actually need to use a real service if you
don't want. You could use a console app to host the service as long as you
want to start it each time (i.e. via boot or from scheduler or something).
The console host is probably easiest during testing, then convert to service
if needed. hth

--
William Stacey [C# MVP]
PCR concurrency library: www.codeplex.com/pcr
PSH Scripts Project www.codeplex.com/psobject
<ol*****@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
|I hope, I misunderstood some basics here and it is easy to solve..
| I need a singleton object running on server which can be used(write
| and read) by different client interfaces - for example there is
| webservice that simply transfer calls to this object and there is a
| COM Interop, that does the same. Also I need to control lifecycle and
| behaviour of this singleton - and for that I am going to have window
| application, that will start and finish it.
| I do not have problem with the last part :) - I run window app and
| request an instance of my singleton. But how can I make another apps
| (webservice and COM interop) to work with the same singleton? I
| believe it is doable, but how?
|
Feb 16 '07 #5

P: n/a
<ol*****@gmail.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
>I hope, I misunderstood some basics here and it is easy to solve..
I need a singleton object running on server which can be used(write
and read) by different client interfaces - for example there is
webservice that simply transfer calls to this object and there is a
COM Interop, that does the same. Also I need to control lifecycle and
behaviour of this singleton - and for that I am going to have window
application, that will start and finish it.
I do not have problem with the last part :) - I run window app and
request an instance of my singleton. But how can I make another apps
(webservice and COM interop) to work with the same singleton? I
believe it is doable, but how?
System.EnterpriseServices is exactly what you are looking for is, derive your class from
ServiceComponent, enable object pooling with max. pool size = 1 and register the class as a
Server type in the COM+ catalog.
Check the docs for details on the attributes you need on the assembly and the class.

Willy.

Feb 16 '07 #6

P: n/a
Marc,
this singleton will serve three tasks - to count a number of connected
users, to log activity and to provide users with application-wide data
in timely manner.
Also this singleton is in charge to update this data from external
source (another WS somewhere over there).
I believe it is pretty common set of tasks. Of course it can be done
in database, but we already have almost all code written and worked in
one-client environment, and all that I want is to adapt it somehow to
work behind webservices and COM.

On Feb 16, 12:20 am, "Marc Gravell" <marc.grav...@gmail.comwrote:
(disclaimer: not a solution)
Can I quickly question *why* you want a system-widesingletonwith
read/write on a web-server? In most cases, this is a bag call: the
write access forces you to make the class thread-safe, which means
that you are serializing all web-requests. This is not a good thing in
terms of scalability. Usually when I see this, the correct answer is
to use a database to handle the centralised access to common data (in
a controlled manner).

One other issue with the above approach is that it also doesn't scale
out if the idea is to have a single version of the truth; in a
cluster, you start having to remote between them to a single throttle-
point (singleton). Database servers are more geared-up to do this job.

Anyway; your scenario could be different, and it might be a good
idea... but worth challenging ;-p

Marc

Feb 16 '07 #7

P: n/a
Will it work on w2k? One of the requirements I have is to make a
server able to be ran on w2k.

On Feb 16, 5:01 am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
<oleg...@gmail.comwrote in message

news:11**********************@a75g2000cwd.googlegr oups.com...>I hope, I misunderstood some basics here and it is easy to solve..
I need asingletonobject running onserverwhich can be used(write
and read) by different client interfaces - for example there is
webservice that simply transfer calls to this object and there is a
COM Interop, that does the same. Also I need to control lifecycle and
behaviour of thissingleton- and for that I am going to have window
application, that will start and finish it.
I do not have problem with the last part :) - I run window app and
request an instance of mysingleton. But how can I make another apps
(webservice and COM interop) to work with the samesingleton? I
believe it is doable, but how?

System.EnterpriseServices is exactly what you are looking for is, derive your class from
ServiceComponent, enable object pooling with max. pool size = 1 and register the class as aServertype in the COM+ catalog.
Check the docs for details on the attributes you need on the assembly and the class.

Willy.

Feb 16 '07 #8

P: n/a
<ol*****@gmail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.com...
Will it work on w2k? One of the requirements I have is to make a
server able to be ran on w2k.
Yep, W2K and up.

Willy.
Feb 16 '07 #9

P: n/a
On Feb 16, 12:03 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
<oleg...@gmail.comwrote in message

news:11*********************@k78g2000cwa.googlegro ups.com...
Will it work on w2k? One of the requirements I have is to make a
serverable to be ran on w2k.

Yep, W2K and up.

Willy.
After reading about COM+ and Remoting I have decided to go with remote
object with WellKnownObjectMode.Singleton.
It works but i have one question of its lifetime. I specified infinite
lease for this object but ..is it indeed infinite? I have Manager app,
and I'd like to kill this object when I click Stop button in Manager.
What is the proper way of doing that?

Feb 16 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.