IClientChannelSink 接口

定义

为客户端信道接收器提供所需的函数和属性。

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

示例

下面的代码示例演示 接口的 IClientChannelSink 实现。

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 ClientSink: public BaseChannelSinkWithProperties, public IClientChannelSink
{
private:

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


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

   virtual Stream^ GetRequestStream( IMessage^ message, ITransportHeaders^ requestHeaders )
   {
      // Get the request stream from the next sink in the chain.
      return (nextSink->GetRequestStream( message, requestHeaders ));
   }

   virtual void ProcessMessage( IMessage^ message, ITransportHeaders^ requestHeaders, Stream^ requestStream, [Out]ITransportHeaders^% responseHeaders, [Out]Stream^% responseStream )
   {
      // Print the request message properties.
      Console::WriteLine( "---- Message from the client ----" );
      IDictionary^ dictionary = message->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( "---------------------------------" );

      // Hand off to the next sink in the chain.
      nextSink->ProcessMessage( message, requestHeaders, requestStream, responseHeaders, responseStream );
   }

   // For synchronous remoting, it is not necessary to implement this method.
   virtual void AsyncProcessRequest( IClientChannelSinkStack^ /*sinkStack*/, IMessage^ /*message*/, ITransportHeaders^ /*requestHeaders*/, Stream^ /*requestStream*/ )
   {
      throw gcnew NotImplementedException;
   }

   virtual void AsyncProcessResponse( IClientResponseChannelSinkStack^ /*sinkStack*/, Object^ /*state*/, 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
   ClientSink( IClientChannelSink^ 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;

public class ClientSink : BaseChannelSinkWithProperties, IClientChannelSink
{

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

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

    public IClientChannelSink NextChannelSink
    {
        get
        {
            return(nextSink);
        }
    }

    public Stream GetRequestStream (IMessage message, ITransportHeaders requestHeaders)
    {
        // Get the request stream from the next sink in the chain.
        return( nextSink.GetRequestStream(message, requestHeaders) );
    }

    public void ProcessMessage (IMessage message,
                                ITransportHeaders requestHeaders,
                                Stream requestStream,
                                out ITransportHeaders responseHeaders,
                                out Stream responseStream)
    {
        // Print the request message properties.
        Console.WriteLine("---- Message from the client ----");
        IDictionary dictionary = message.Properties;
        foreach (Object key in dictionary.Keys)
        {
            Console.WriteLine("{0} = {1}", key, dictionary[key]);
        }
        Console.WriteLine("---------------------------------");

        // Hand off to the next sink in the chain.
        nextSink.ProcessMessage(message, requestHeaders, requestStream, out responseHeaders, out responseStream);
    }

    // For synchronous remoting, it is not necessary to implement this method.
    public void AsyncProcessRequest (IClientChannelSinkStack sinkStack,
                                     IMessage message,
                                     ITransportHeaders requestHeaders,
                                     Stream requestStream)
    {
        throw new NotImplementedException();
    }

    public void AsyncProcessResponse (IClientResponseChannelSinkStack sinkStack,
                                      Object state,
                                      ITransportHeaders responseHeaders,
                                      Stream responseStream)
    {
        throw new NotImplementedException();
    }

    // Constructor
    public ClientSink (IClientChannelSink sink) {
      if (sink == null) throw new ArgumentNullException("sink");
      nextSink = sink;
    }
}

IClientChannelSinkProvider有关相应客户端接收器提供程序实现的示例,请参阅接口文档。

注解

通道接收器提供了一个插件点,允许访问流经通道的基础消息以及传输机制用于将消息发送到远程对象的流。 通道接收器在通道接收器提供程序链中链接在一起,所有通道消息在序列化和传输之前都流经此接收器链。

属性

NextChannelSink

获取客户端接收器链中的下一个客户端信道接收器。

Properties

获取可以通过其访问接收器的属性的字典。

(继承自 IChannelSinkBase)

方法

AsyncProcessRequest(IClientChannelSinkStack, IMessage, ITransportHeaders, Stream)

请求异步处理对当前接收器的方法调用。

AsyncProcessResponse(IClientResponseChannelSinkStack, Object, ITransportHeaders, Stream)

请求异步处理对当前接收器上的方法调用的响应。

GetRequestStream(IMessage, ITransportHeaders)

返回所提供的消息将要序列化到的 Stream

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

请求从当前接收器处理消息。

适用于

另请参阅