How Do I...Create a Remote Object as a Singleton?
This example demonstrates how to modify the Client/Server example
by deploying the remote object as a
singleton. The client starts two threads and calls the CountMe method on
the server on two different channels: TCP and HTTP.
Although this example is very
simple, it does illustrate a few important concepts.
- The HelloServer object is only activated once and its destructor is never called.
- When you run the client, thread number two appears to outperform thread number one. The second
thread is indeed faster than the first since thread one uses the HTTP channel that
transports data in XML using SOAP while TCP uses a binary transport.
While TCP clearly outperforms HTTP, the latter is more general and should be
used when communicating with unknown endpoints.
- The server object is locked while the counter is incremented in the CountMe call.
- Notice that the count returned by the server is not reset between different
invocations of the client. This behavior demonstrates that the server does
preserve its state during its lifetime.
- Each client thread makes a call to the server and then yields control to
its partner to ensure they both get a chance to run.
- Each thread registers its own channel and connects to the server using
different URIs. These are "http://localhost:8086/SayHello" for thread
one and "tcp://localhost:8085/SayHello" for thread two.
- The client executable waits for both threads to finish before terminating.
NOTE: Do not specify a port number when registering the client channels. The
framework uses the port number on the channels to determine if the
channel should listen or connect. When the channel is registered with
a port number, the channel listens. If the port number is zero, it
attempts to connect to a remote channel at the specified URI.
VB Singleton Sample
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\HowTo\Samples\Remoting\singleton\]
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.
|