1. Introduction
In the previous two articles we saw the server activated, single call remote objects. Also remember, each call to the server will create a new remote object in the Single call technique. In this article we will see how the Singleton remote objects works. Then we will walk through an example.
The example here does not require a big explanation, as you are already familiar with the remoting by previous article on the remoting topic.
2. Server activated, Singleton remote object
In this technique also, the object is created by the server and will be kept in the server's remote object pool. Unlike the single call technique, here only one object is created and maintained in the memory pool. All client applications access the same remote objects. That is why we call this remote object a singleton remote object.
To better understand the usage of Singleton remote object, a simple application is created.
3. The application
As I have already said, there is not much explanation required on the coding side. You just need to say that you want to register the object as singleton remote object. That is all. Everything else is taken care of by the server application. The following is the change that you should know:
RemotingConfiguration.RegisterWellKnownServiceType(typeof(SingletonServer.RegVotes), "RegVotes", WellKnownObjectMode.Singleton);
Deploy the Server on one machine. Run the client application from the different machine to see how it works.
Below is the Screen shot taken when I am running two clients:
In this example all the clients access the remote object RegVotes. This object is registered as singleton object so the server maintains the single copy of the object. All the clients share that single object. You can select one of the voting options and click the Vote now button. The server returns the average rating after the client's vote is registered.
4. Search Tags
Once you open the solution (Solution file you can find inside the SingletonServer folder) use the following tags to search the projects:
//Client
//Server
You will get the entire step, which is exactly equal to the previous applications. And differs only in the place when registering the objects using RegisterWellKnownServiceType.
5. Previous Articles
This article may be confusing for you if you are reading it without reading the previous parts. The links below get you to the previous two parts:
Remoting: Part 1, Part 2
Note: The application created in VS2005 IDE. If you have latest version say yes to the conversion dialog/Wizard.