WebReference.com - Part 2 of Chapter 6: Professional C# Web Services, from Wrox Press Ltd (8/8)
[previous] |
Professional C# Web Services
To see the sponsor in action we'll add a for loop to the Main() method in the file
SimpleClient.cs. The time to sleep is longer than the configured RenewalTime,
so we should see calls to the sponsor:
for (int i=0; i < 20; i++)
{
DisplayLease("In loop: " + i, obj);
obj.Hello();
Thread.Sleep(25000);
}
We have to change the configuration files and use the TcpChannel instead of the
TcpClientChannel in the client configuration file SimpleClient.exe.config,
because this channel has the functionality of both a client and server channel. If we start both the
client and server application on the same system, we also have to configure a different port. Here
I'm using port 9002, so we can run the application on a single system:
<channels>
<channel ref="tcp" port="9002" />
</channels>
The server configuration file SimpleServer.exe.config needs a similar change:
<channels>
<channel ref="tcp" port="9000" />
</channels>
Running the Example
The console output of the client application in the screenshot below lists the lease times of the
remote object. The first line shows a lease time value that is near to 60 seconds; this was the initial
lease time. 25 seconds later the second iteration of the loop happened. The garbage collection doesn't
happen immediately after the time 0 is reached, so the remote object was lucky that the lease time
was extended twice to 20 seconds after a wait (loops 2 and 3), but the Renewal() method
still wasn't called. Before loop 4, the Renewal() method was called for the first time,
and here the lease was extended to the value that the sponsor supports, 2 minutes. The lease time
again is decremented, before Renewal() is called again before loop 10:

Remote Object Types Summary
We have now seen the types of the remote objects and their purpose. Let's summarize the features of these objects in the following table.
| Object Type | Time of Object Activation | State | Leasing |
Well-known SingleCall |
With every method call | Stateless | No |
Well-known Singleton |
Only once with the first method call | State shared for all clients | Yes |
| Client-Activated | When the client instantiates the remote object | State | Yes |
[previous] |
Created: February 25, 2002
Revised: February 25, 2002
URL: http://webreference.com/programming/csharp/webservices/chap6/2/8.html

Find a programming school near you