February 28, 2011

.Net Remoting - Singleton Server Activated

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 work. 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 the 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 as singleton remote object.

To better understand the usage of Singleton remote object, a simple application is created.

3. The application

As I already told, there is no much explanation is 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 by the server application. Below is the change that you should know:


Deploy the Server on one machine. Run the client application from the different machine to see how it works. 

Below is the Screenshot of a server and two clients: 

Fig 1. Example - Singleton Server Activated

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 the voting option and click the Vote now button. The server returns the average rating after 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:


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:

Look at the "remoting" label for other articles on remoting.

Note: The application created in VS2005 IDE. If you have the latest version say yes to the conversion dialog/Wizard.

Source Code : Download

No comments:

Post a Comment

Leave your comment(s) here.

Like this site? Tell it to your Friend :)