Implementing the IFormatter Deserialize Method

The function of the IFormatter.Deserialize method is to deserialize an object graph from a stream and return the root object of the object graph. The following code implements the IFormatter.Deserialize method for the MyFormatter class object Deserialize(System.IO.Stream serializationStream) Create an object manager to help with deserialization. _om new ObjectManager( _surrogateselector, _streamingcontext ) _reader new StreamReader(serializationStream) Read objects until end of stream. Now we...

Contexts and Remoting

Recall that the context forms a .NET Remoting boundary around object instances within it. Figure 6-1 illustrates how the .NET Remoting infrastructure isolates an object instance within a context from object instances outside the context by using a special type of channel known as a cross-context channel and four chains of message sinks that separate inbound message processing from outbound message processing. Figure 6-1 Chains of message sinks isolate a ContextBoundObject instance from objects...

Message Sink

Any type that implements the IMessageSink interface can participate in the .NET Remoting architecture as a message sink. Table 6-1 lists the members of the IMessageSink interface. Table 6-1 Members of Table 6-1 Members of The next message sink in the chain, or null if this is the last sink in the chain Processes the message asynchronously The following code defines a class that implements IMessageSink public class PassThruMessageSink IMessageSink public PassThruMessageSink IMessageSink next...

Context Attributes and Properties

You define and establish a context by attributing the context-bound type with one or more attributes that implement the IContextAttribute interface. Table 6-2 shows the methods that IContextAttribute defines. Table 6-2 Members of Table 6-2 Members of The runtime calls this method to determine whether the current context is OK for activation of the attributed type. The runtime calls this method after an attribute has indicated that the current context isn't OK for activation of the attributed...

Creating a Custom Dynamic Sink

To create a custom dynamic context sink, you need to perform the following tasks Define a dynamic message sink class that implements the IDynamicMessageSink interface. Define a dynamic property class that implements the IDynamicProperty and the IContributeDynamicSink interfaces. In the implementation of the IContributeDynamicSink.GetDynamicSink method, return an instance of the dynamic message sink class. Programmatically register and unregister the dynamic property by using the...

Client FormatterSink Provider

Now that we have a client formatter sink, we need a channel sink provider class that we can use to install the formatter sink into the client channel sink chain. The following code listing defines the MyFormatterClientSinkProvider class public class MyFormatterClientSinkProvider IC1ientFormatterSinkProvider public MyFormatterClientSinkProvider i I public MyFormatterClientSinkProvider IDictionary properties, ICollection providerData Build the client-side channel sink chain public...

Client Formatter Sink

The first sink in the client-side channel sink chain is an instance of a client formatter sink that implements the IClientFormatterSink interface. The client formatter sink acts as a bridge between the message sink chain and the channel sink chain. As such, the client formatter sink is both a message sink and a channel sink. The IClientFormatterSink interface is a composite of the IMessageSink, IClientChannelSink, and IChannelSinkBase interfaces. The following code listing defines a class named...

Finally the message contains information identifying the calling application domain context and process as well as

lt SOAP-ENC Array id ref-18 lt item href ref-42 gt lt item href ref-43 gt lt SOAP-ENC Array gt lt a3 CrossAppDomainData id ref-42 lt _DomainID gt 1 lt _DomainID gt lt _processGuid id ref-44 gt 20c23b9b_4d09_46a8_bc29_10037f04f46f lt _processGuid gt lt a3 CrossAppDomainData gt lt a3 ChannelDataStore id ref-43 lt _channelURIs href ref-45 gt lt _extraData xsi null 1 gt lt a3 ChannelDataStore gt lt SOAP-ENC Array id ref-45 lt item id ref-4 lt SOAP-ENV Body gt lt SOAP-ENV Envelope gt

Process Message is where we allow or deny method calls If we arent in a blocked time period we call Process Message on

Client know we couldn't fulfill its request. Here's the implementation of ProcessMessage public ServerProcessing ProcessMessage IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream If we are not in a blocked time period, send the message down the chain. return m_NextSink.ProcessMessage sinkStack, requestMsg, requestHeaders, requestStream, out...

Server FormatterSink Provider

Now that we have a server formatter sink, we need a channel sink provider class that we can use to install the formatter sink into the server channel sink chain. The following code listing defines the MyFormatterServerSinkProvider class public class MyFormatterServerSinkProvider public MyFormatterServerSinkProvider This ctor form provides properties from configuration file, public MyFormatterServerSinkProvider IDictionary properties, private IServerChannelSinkProvider _Next public...

Singleton

No more than one instance of a Singleton-mode-configured type will be active at any time. An instance is activated when first accessed by a client if no other instance exists. While active, the Singleton instance will handle all subsequent client access requests by either the same client or other clients. The Singleton instance can maintain state between method calls. The following code snippet shows the programmatic method of configuring a remotable object type as a Singleton in a server...