This documentation is archived and is not being maintained.

IServerChannelSink Interface

Provides methods used for security and transport sinks.

Namespace:  System.Runtime.Remoting.Channels
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public interface IServerChannelSink : IChannelSinkBase

Channel sinks provide a plug-in point that allows access to the underlying messages flowing through the channel as well as the stream used by the transport mechanism to send messages to a remote object. Channel sinks are linked together in a chain of channel sink providers, and all channel messages flow through this chain of sinks before the message is serialized and transported.

The following code example illustrates an implementation of the IServerChannelSink interface.

using System;
using System.Collections;
using System.IO;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Messaging;
using System.Security.Permissions;

public class ServerSink : BaseChannelSinkWithProperties, IServerChannelSink
{

    // This class inherits from BaseChannelSinkWithPropertes 
    // to get an implementation of IChannelSinkBase. 


    // The next sink in the chain. 
    private IServerChannelSink nextSink;

    public IServerChannelSink NextChannelSink
    {
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
        get
        {
            return(nextSink);
        }
    }

    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
    public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack,
                                     Object state,
                                     IMessage message,
                                     ITransportHeaders responseHeaders)
    {
        return(null);
    }

    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
    public ServerProcessing ProcessMessage (IServerChannelSinkStack sinkStack,
                                            IMessage requestMessage,
                                            ITransportHeaders requestHeaders,
                                            Stream requestStream,
                                            out IMessage responseMessage,
                                            out ITransportHeaders responseHeaders,
                                            out Stream responseStream)
    {

        // Hand off to the next sink for processing.
        sinkStack.Push(this, null);
        ServerProcessing status = nextSink.ProcessMessage(
          sinkStack, requestMessage, requestHeaders, requestStream,
          out responseMessage, out responseHeaders, out responseStream
        );

        // Print the response message properties.
        Console.WriteLine("---- Message from the server ----");
        IDictionary dictionary = responseMessage.Properties;
        foreach (Object key in dictionary.Keys)
        {
            Console.WriteLine("{0} = {1}", key, dictionary[key]);
        }
        Console.WriteLine("---------------------------------");

        return(status);
    } 

    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
    public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack,
                                      Object state,
                                      IMessage message,
                                      ITransportHeaders responseHeaders,
                                      Stream responseStream)
    {
        throw new NotImplementedException();
    }

    // Constructor
    [SecurityPermission(SecurityAction.LinkDemand)]
    public ServerSink (IServerChannelSink sink) {
      if (sink == null) throw new ArgumentNullException("sink");
      nextSink = sink;
    }


}
#using <mscorlib.dll>
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Collections;
using namespace System::IO;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Messaging;

public __gc class ServerSink : public BaseChannelSinkWithProperties, public IServerChannelSink
{

    // This class inherits from BaseChannelSinkWithPropertes
    // to get an implementation of IChannelSinkBase.


    // The next sink in the chain.
private:
    IServerChannelSink* nextSink;

public:
    __property IServerChannelSink* get_NextChannelSink()
    {
        return(nextSink);
    }


public:
    Stream* GetResponseStream (IServerResponseChannelSinkStack* /*sinkStack*/,
        Object* /*state*/,
        IMessage* /*message*/,
        ITransportHeaders* /*responseHeaders*/)
    {
        return(0);
    }

public:
    ServerProcessing ProcessMessage (IServerChannelSinkStack* sinkStack,
        IMessage* requestMessage,
        ITransportHeaders* requestHeaders,
        Stream* requestStream,
        [Out]IMessage** responseMessage,
        [Out]ITransportHeaders** responseHeaders,
        [Out]Stream** responseStream)
    {

        // Hand off to the next sink for processing.
        sinkStack->Push(this, 0);
        ServerProcessing status = nextSink->ProcessMessage(
            sinkStack, requestMessage, requestHeaders, requestStream,
            responseMessage, responseHeaders, responseStream
            );

        // Print the response message properties.
        Console::WriteLine(S"---- Message from the server ----");
        IDictionary* dictionary = (*responseMessage)->Properties;
        IEnumerator* myEnum = dictionary->Keys->GetEnumerator();
        while (myEnum->MoveNext())
        {
            Object* key = __try_cast<Object*>(myEnum->Current);
            Console::WriteLine(S"{0} = {1}", key, dictionary->Item[key]);
        }
        Console::WriteLine(S"---------------------------------");

        return(status);
    } 

public:
    void AsyncProcessResponse (IServerResponseChannelSinkStack* /*sinkStack*/,
        Object* /*state*/,
        IMessage* /*message*/,
        ITransportHeaders* /*responseHeaders*/,
        Stream* /*responseStream*/)
    {
        throw new NotImplementedException();
    }

    __property System::Collections::IDictionary* get_Properties()
    {
        return (dynamic_cast<BaseChannelSinkWithProperties*>(this))->Properties;
    }

    // Constructor
public:
    ServerSink (IServerChannelSink* sink) {
        if (sink == 0) throw new ArgumentNullException(S"sink");
        nextSink = sink;
    }


};

See the IServerChannelSinkProvider interface documentation for an example of the corresponding server sink provider implementation.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: