views:

39

answers:

1

Both perform the same operation that is

MSDN

  • Singleton: ""Single Call objects service one and only one request coming in.... "
  • CAO: "Client-activated objects (CAO) are server-side objects that are activated upon request from the client...."

in both cases, data is not shared, but in singleton only once client can be connected at a time, why would someone want that Under what scenario is Singleton useful and are there any more differences in them ?

A: 

You missread the lines. Here´s the definition from the MSDN. I highlight (bold) some diffrences between those objects.

  • Single Call

    Single Call objects service one and only one request coming in. Single Call objects are useful in scenarios where the objects are required to do a finite amount of work. Single Call objects are usually not required to store state information, and they cannot hold state information between method calls. However, Single Call objects can be configured in a load-balanced fashion.

  • Singleton Objects

    Singleton objects are those objects that service multiple clients and hence share data by storing state information between client invocations. They are useful in cases in which data needs to be shared explicitly between clients and also in which the overhead of creating and maintaining objects is substantial.

  • Client-Activated Objects (CAO)

    Client-activated objects (CAO) are server-side objects that are activated upon request from the client. This way of activating server objects is very similar to the classic COM coclass activation. When the client submits a request for a server object using "new" operator, an activation request message is sent to the remote application. The server then creates an instance of the requested class and returns an ObjRef back to the client application that invoked it. A proxy is then created on the client side using the ObjRef. The client's method calls will be executed on the proxy. Client-activated objects can store state information between method calls for its specific client and not across different client objects. Each invocation of "new" returns a proxy to an independent instance of the server type.

State Information is some data that you store in variables or properties of the object, to process the client request.

Since a Single call object is created when a client request it to do some work, and destroyed after it has done work, it cannot hold state information, cause each request creates a new object (It can load and store data in a datasource, to do it´s work).

A Singleton object is created only once (maybe at server starup) and lifes as long as the server process is running. It can store information in variables and properties to handle client requests, cause each client works with the same object and it isn´t destroyed after a client call.

An easy example to display the diffrence betwenn a single call and singleton object is to create a method Increment() to increment a variable (integer) in the object and write the variable to the Console. The single call object will always print the same value to the Console (1 if the variable starts with 0), while the singleton object will always print an incremented value (1, 2, 3, etc.) after each call.

Jehof
oh, so what does state information mean ?(sorry for a another noobish question after a good answer)
KiNGPiN
@KiNGPiN: I have updated my answer with some info about "state information"
Jehof
ooh, great ... got it Thankyou :)
KiNGPiN