he remoting framework in .NET contains a feature set designed to support intra-process communications and application integration functions; however, for many applications the default remoting behaviors may not deliver all the features that you need. For example, what if you want to implement an encryption scheme that secures the messaging layer for your remoting application? To do so, you can make both the client and the server application aware of the encryption and decryption requirements for the messages, but that will require some redundant code for both client and server that you can't easily leverage across applications. In contrast, using the extensibility features built into the .NET remoting framework lets you customize the remoting processes to suit your application's needs. This article shows you how to build a custom message serialization sink for a sample remoting application that captures SOAP messages and serializes data to the remoting client's file system.
Understanding .NET Remoting Infrastructure
To understand how to extend.NET remoting using custom sinks, you must first understand a little about how the remoting infrastructure works. The basic building blocks of the remoting architecture include:
- Proxy objects used to forward calls to remote objects
- Message objects used to carry the necessary data to invoke a remote method
- Message sink objects used to process messages for remote method calls
- Formatter objects used to serialize the message formats for transfer
- Transport channel objects used to transfer the serialized messages from one process to another.
|Using the extensibility features built into the .NET remoting framework lets you customize the remoting processes to suit your application's needs.|
For the remoting extension example in this article, pay close attention to the message sink objects and the formatters and transport channels, because they are key features in enabling the remoting infrastructure to support method invocations. Each call to a remote object reference generates a message that serves as a container for data exchanges. Message objects are dictionary objects encapsulated by the IMessage interface. Each message involved in a remoting call passes through a chain of message sinks. Message sinks are objects that cooperate to receive notifications for messages and process those messages. There are sinks on both the client and server sides of a remoting call. Each message sink passes the message to the next sink in the chain both before and after the message is transported.
Included in these message sinks are formatter sinks which serve to encode the data contained by the message into a format suitable for transmission over the wire. By default, .NET remoting supports both a SOAP formatter sink and a binary formatter sink, but you can extend the remoting infrastructure to support custom formatters.