5.5.2. P~DotNet

C:SDotNetScha_5>csc /v:helloservice.exe helloclientca2-cs

Microsoft <R> Uisual C8 Compiler version 7.00.9254 [CLP version ui.0.2914] Copyright <C> Microsoft Corp 2000-2001. All rights reserved.

C: \Do t Ne t \c ha_5 >he 1 lo c 1 ie n t c a2 starting HTTP Hello client... Hello, Joe Bloggsf Hello, Mary Bloggsf CurrentGtate : Active

CurrentLeaseTime : 00:04:59.9090000 InitialLeaseTime : 00:05:00 ReneuOnCallTine : 00:02:00

Hello, Joe Bloggsf Hello, Mary Bloggsf CurrentGtate : Active

CurrentLeaseTirae : 00:04:49.8450000 InitialLeaseTime : 00:05:00 ReneuOnCallTine : 00:02:00


C:\Do t Ne t\c ha_5 >_

Figure 5.9 Displaying the lease information

Note the lease information. The CurrentState property indicates that the lease is active. Possible values for the CurrentState property are:

Null (The lease is not initialized)





The InitialLeaseTime is 5 minutes by default, and this is the starting value for CurrentLeaseTime which is displayed above as 4:59.9090000 seconds. The program sleeps for 10 seconds before reinvoking the remote object's Greet method. By then, the value for CurrentLeaseTime has reduced to 4:49.8450000 seconds. The lease time continues to diminish toward expiration in this way. When it falls below the RenewOnCallTime, which is 2 minutes in this example, every subsequent method invocation resets the lease duration back to 2 minutes. In this way, provided the object is referenced at least once every 2 minutes (the RenewOnCall-Time), the reference will remain alive. If the lease expires, a RemotingException will be raised stating that the service has disconnected.5.5.2 Amending the lease

Both remote object and client can amend the lease. The remote object, which derives from MarshalByRefObject, can override the MarshalByRefOb-ject.InitializeLifetimeService method and set values for the Ini-tialLeaseTime, RenewOnCallTime, and so forth, before the lease becomes active. A better approach is to place these values in the server's configuration file. For example, the following entry in the server's configuration file sets the Initial-LeaseTime to 24 hours (1D) and the RenewOnCallTime, for connecting clients, to 15 minutes (15M):


<system.runtime.remoting> <application>


</service> <channels>


<!-- set lease parameters -- > <lifetime leaseTime = "1D"

renewOnCallTime = "15M"


</application> </system.runtime.remoting> </configuration>

However, increasing the lease duration on the server-side increases the lease duration for all clients, thus increasing the server burden. If a particular client requires a longer lease, this can be done by implementing a callback sponsor in the client.