IServerChannelSink 接口

定义

提供用于安全和传输接收器的方法。Provides methods used for security and transport sinks.

public interface class IServerChannelSink : System::Runtime::Remoting::Channels::IChannelSinkBase
public interface IServerChannelSink : System.Runtime.Remoting.Channels.IChannelSinkBase
[System.Runtime.InteropServices.ComVisible(true)]
public interface IServerChannelSink : System.Runtime.Remoting.Channels.IChannelSinkBase
type IServerChannelSink = interface
    interface IChannelSinkBase
[<System.Runtime.InteropServices.ComVisible(true)>]
type IServerChannelSink = interface
    interface IChannelSinkBase
Public Interface IServerChannelSink
Implements IChannelSinkBase
派生
属性
实现

示例

下面的代码示例演示接口的实现 IServerChannelSinkThe following code example illustrates an implementation of the IServerChannelSink interface.

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;

[System::Security::Permissions::PermissionSet(System::Security::
   Permissions::SecurityAction::Demand, Name = "FullTrust")]
public ref class ServerSink: public BaseChannelSinkWithProperties, public IServerChannelSink
{
private:

   // This class inherits from BaseChannelSinkWithPropertes
   // to get an implementation of IChannelSinkBase.
   // The next sink in the chain.
   IServerChannelSink^ nextSink;

public:
   property IServerChannelSink^ NextChannelSink 
   {
      virtual IServerChannelSink^ get()
      {
         return (nextSink);
      }
   }

   virtual Stream^ GetResponseStream( IServerResponseChannelSinkStack^ /*sinkStack*/, Object^ /*state*/, IMessage^ /*message*/, ITransportHeaders^ /*responseHeaders*/ )
   {
      return nullptr;
   }

   virtual 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, nullptr );
      ServerProcessing status = nextSink->ProcessMessage( sinkStack, requestMessage, requestHeaders, requestStream, responseMessage, responseHeaders, responseStream );

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

      Console::WriteLine( "---------------------------------" );
      return (status);
   }

   virtual void AsyncProcessResponse( IServerResponseChannelSinkStack^ /*sinkStack*/, Object^ /*state*/, IMessage^ /*message*/, ITransportHeaders^ /*responseHeaders*/, Stream^ /*responseStream*/ )
   {
      throw gcnew NotImplementedException;
   }

   property System::Collections::IDictionary^ Properties 
   {
      virtual System::Collections::IDictionary^ get() override
      {
         return (dynamic_cast<BaseChannelSinkWithProperties^>(this))->Properties;
      }
   }

   // Constructor
   ServerSink( IServerChannelSink^ sink )
   {
      if ( sink == nullptr )
            throw gcnew ArgumentNullException( "sink" );

      nextSink = sink;
   }
};
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;
    }
}

IServerChannelSinkProvider有关相应的服务器接收器提供程序实现的示例,请参阅接口文档。See the IServerChannelSinkProvider interface documentation for an example of the corresponding server sink provider implementation.

注解

信道接收器提供了一个插件点,该插件点允许访问流过通道的基础消息,以及用于将消息发送到远程对象的传输机制所使用的流。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.

属性

NextChannelSink

获取服务器接收器链中的下一个服务器信道接收器。Gets the next server channel sink in the server sink chain.

Properties

获取可以通过其访问接收器的属性的字典。Gets a dictionary through which properties on the sink can be accessed.

(继承自 IChannelSinkBase)

方法

AsyncProcessResponse(IServerResponseChannelSinkStack, Object, IMessage, ITransportHeaders, Stream)

请求从当前接收器对异步发送的方法调用的响应进行处理。Requests processing from the current sink of the response from a method call sent asynchronously.

GetResponseStream(IServerResponseChannelSinkStack, Object, IMessage, ITransportHeaders)

返回提供的响应消息将序列化到其上的 StreamReturns the Stream onto which the provided response message is to be serialized.

ProcessMessage(IServerChannelSinkStack, IMessage, ITransportHeaders, Stream, IMessage, ITransportHeaders, Stream)

请求从当前接收器处理消息。Requests message processing from the current sink.

适用于