WebReference.com - Part 1 of Chapter 6: Professional C# Web Services, from Wrox Press Ltd (7/8)
[previous] [next] |
Professional C# Web Services
More .NET Remoting
As we have seen it was an easy task to build a simple client and server. We created a remote object that will run on the server, and registered a channel using a configuration file. For simple remoting applications that's all what is needed, but a lot more is possible with .NET Remoting. Let us discuss some terms of the architecture:
Remote Objects
As we have seen now, a remote object class must derive from the class
MarshalByRefObject. Calling this object across application domains requires a proxy. .NET Remoting supports two types of remote objects: well-known and client-activated. For well-known objects a URI is used for identification. The client uses the URI to access such objects, which is why they are called well-known. For well-known objects we have two modes: SingleCall and Singleton. With aSingleCallobject, the object is created new with every method call; it is a stateless object. ASingletonobject is created only once.Singletonobjects share state for all clients.The other object type that is supported with .NET Remoting is client-activated. This object type uses the type of the class for activation. The URI is created dynamically behind the scenes and returned to the client. In further calls to the remote object this URI is used automatically to call methods in the same instance that was created. Client-activated objects are stateful.
Activation
Well-known
SingleCallobjects are not created at the time when the client invokes thenewmethod. Instead, they are created with every method call. They could also be called server-activated. Client-activated objects are created at the time when the client instantiates the object; that's why they are called client-activated. In both cases the client gets a proxy of the remote object. We have to differentiate a transparent proxy from a real proxy. The transparent proxy is created dynamically using the metadata of the remote object class. At proxy creation the methods and arguments of the public methods of the remote object are read from the metadata, and the proxy makes these methods available to the client. For the client the transparent proxy looks like the remote object class, but instead it calls methods of the real proxy to send the method calls across the network.Marshaling
The process when data is sent across application domains is called marshaling. Sending a variable as argument of a remote method, this variable must be converted so that it can be sent across application domains. We differentiate two kinds of marshaling: Marshal-by-value (MBV) and Marshal-by-reference (MBR). With Marshal-by-value the data is serialized to a stream, and this stream is sent across. Marshal-by-reference creates a proxy on the client that is used to communicate with the remote object.
Interception
To fully understand the remoting architecture we have to discuss interception. With interception we can put some functionality into the method call chain. For example, if we call a method of an object, the interception layer could catch the call to convert the method call, or do some logging. Interception is used in every part of the call chain with .NET remoting.
For interception sink objects are used. A sink can perform some actions with messages it receives, for example conversions or logging. Sinks are connected in sink chains; one sink passes the message to the next sink. We can differentiate formatter sinks, custom channel sinks, and transport sinks. Formatter sinks transform the messages into a message stream. The transport sink is the last sink in the chain in the client to send the message into the channel, and the first sink in the server to receive the message. Transport sinks are built into the channel. With custom channel sinks the interception mechanism can be used to add custom functionality to read and write the data received and implement logging, add additional headers, or to redirect messages, for example.
Now that we are more familiar with remoting terms we can look into the classes of the remoting namespace.
[previous] [next] |
Created: February 13, 2002
Revised: February 13, 2002
URL: http://webreference.com/programming/csharp/webservices/chap6/1/7.html

Find a programming school near you