19
Distributed Systems Tutorial 3 - .NET Remoting – Crossing Application Boundaries

Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

Distributed Systems

Tutorial 3 - .NET Remoting – Crossing Application Boundaries

Page 2: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

2

In this tutorial, we will look at the overall sequence of events that occurs when a client of a remote object activates the object and then calls a method on that object.

Reminder: To enable objects in other application domains to use an instance of

the class, the class must inherit from MarshalByRefObjet How does .NET Remoting enable objects to communicate

across .NET Remoting boundaries? Answer:

The client uses a proxy object to interact with the remote object by using some means of inter process communication.

Page 3: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

3

Transparent Proxy

The transparent proxy is the one that the client directly accesses. Transparent Proxy instance has an interface identical to the

interface of the remote object. When a client makes a method call on the transparent proxy, the

proxy simply forwards the message to the second proxy type, RealProxy.

Page 4: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

4

Real Proxy

The real proxy takes the message created by the transparent proxy and sends it to the .NET Remoting infrastructure for eventual delivery to the remote object.

The System.Runtime.Remoting.Proxies.RealProxy type is an abstract class

.NET Remoting infrastructure defines a RemotingProxy class that extends RealProxy.

You can derive your own custom proxy type from RealProxy and use it in place of the one provided by the runtime.

Page 5: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

5

Page 6: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

6

Messages

Encapsulating the information about the method call in a message object abstracts and models the method−call in an object−oriented way.

.NET Remoting uses messages to enable distributed objects to interact with one another.

Message objects encapsulate all method calls, input arguments, method return values, output arguments, exceptions, and so on.

The message conveys all this information from the caller to the callee.

Page 7: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

7

.NET Remoting message object types implement the System.Runtime.Remoting.Messages.IMessage interface and are serializable.

Only instances of serializable types can cross .NET Remoting boundaries.

This means that any object placed in the message must be serializable if you want it to flow across the .NET Remoting boundary with the message.

Page 8: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

8

Channels

.NET Remoting transports serialized message objects across .NET Remoting boundaries through channels.

The .NET Remoting infrastructure provides two types of channels you can use to provide a transport mechanism for your distributed applications: TCP and HTTP.

The channel architecture provides flexibility by employing a series of channel sink objects linked together into a sink chain.

Page 9: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

9

Each channel sink in the chain has a clearly defined role in the processing of the message.

Each channel sink performs the following tasks: Accepts the message and a stream from the previous sink in the

chain Performs some action based on the message or stream Passes the message and stream to the next sink in the chain

Page 10: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

10

Client−side channel architecture

Page 11: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

11

In the previous slide, the client object makes calls on a transparent proxy, which in turn converts the method call into a message object and passes that object to the RealProxy—actually a RemotingProxy derived from RealProxy.

The RemotingProxy passes the message object to a set of specialized sink chains within the context (not shown in the slide).

The message object makes its way through the context sink chains until it reaches the first sink in the channel's sink chain: a formatter sink

Formatter Sink is responsible for serializing the message object to a byte stream by using a particular wire format.

The formatter sink then passes the stream to the next sink in the chain for further processing.

The last sink in the channel sink chain is responsible for transporting the stream over the wire by using a specific transport protocol.

Page 12: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

12

Transport sink

A transport sink terminates the client−side channel sink chain. When this sink receives the message stream, it first writes

transport protocol header information to the wire and then copies the message stream to the wire, which transports the stream across the .NET Remoting boundary to the server−side .

Page 13: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

13

Server−side channel architecture

Page 14: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

14

The first sink on the server−side channel sink chain that the serialized message stream encounters is a transport sink that reads the transport protocol headers and the serialized message data from the stream.

After pulling this data off the wire, the transport sink passes this information to the next sink in the server−side sink chain.

Sinks in the chain perform their processing and pass the resulting message stream and headers up the channel sink chain until they reach the formatter sink.

The formatter sink deserializes the message stream and headers into an IMessage object and passes the message object to the .NET Remoting infrastructure's StackBuilderSink

StackBuilderSink actually makes the method call on the remote object. StackBuilderSink converts the message into a stack based method call to the

target object.

Page 15: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

15

When the method call returns, the StackBuilderSink packages the return result and any output arguments into a message object of type System.Runtime.Remoting.Messaging.ReturnMessage, and then passes back it down the sink chain for eventual delivery to the proxy in the caller's .NET Remoting subdivision.

Page 16: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

16

Server & Client architecture

Page 17: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

17

Custom Sink

As shown in the previous slide, it is possible to add custom sinks to the chain, both on the client side and server side.

So when do we decide to develop our own custom sink? Answer:

We usually do it when we want to inspect or modify the data sent from the proxy to the remote object and / or the data returned from the remote object back to the proxy.

For example: You want to encrypt the information sent over the wire between the client and the server.

Custom sinks can be placed either before or after the formatter sink, depending on whether they are designed to manipulate the message or the serialized stream.

Page 18: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

18

Where should we locate a custom sink that responsible for encryption of the data ?

Answer: The encryption custom sink would want to work on the stream (it

doesn’t care about the logical meaning of the message; it just needs to scramble it).

Therefore the client-side custom sink should be situated after the formatter sink (after the message is serialized to a stream) while the server-side custom sink should be situated before the formatter sink (before the stream is diserialized back to a message).

Page 19: Distributed Systems Tutorial 3 -.NET Remoting – Crossing Application Boundaries

19

What should you do if you want the client to send username and password information and the server, which should examine them before allowing access to the target object ?

Answer: you can create a client-side custom sink that adds the username and

password to every outgoing message and a server-side custom sink that retrieves this information and throws an exception (which will be propagated back to the client) if the username and / or password are invalid. Since these custom sinks work on the message, rather than on the serialized stream, the client-side custom sink should be placed before the formatter sink (before the message is serialized to a stream) and the server-side custom sink should be placed after the formatter sink (after the stream is desterilized back to a message).