Condividi tramite


IServerChannelSink Interfaccia

Definizione

Fornisce i metodi utilizzati per i sink di trasporto e di sicurezza.

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
Derivato
Attributi
Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrata un'implementazione dell'interfaccia IServerChannelSink .

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;

public class ServerSink : BaseChannelSinkWithProperties, IServerChannelSink
{
    // This class inherits from BaseChannelSinkWithProperties
    // to get an implementation of IChannelSinkBase.

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

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

    public Stream GetResponseStream (IServerResponseChannelSinkStack sinkStack,
                                     Object state,
                                     IMessage message,
                                     ITransportHeaders responseHeaders)
    {
        return(null);
    }

    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);
    }

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

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

Per un esempio dell'implementazione del provider sink del server corrispondente, vedere la IServerChannelSinkProvider documentazione dell'interfaccia.

Commenti

I sink di canale forniscono un punto di plug-in che consente l'accesso ai messaggi sottostanti che passano attraverso il canale e il flusso usato dal meccanismo di trasporto per inviare messaggi a un oggetto remoto. I sink di canale sono collegati in una catena di provider di sink del canale e tutti i messaggi del canale passano attraverso questa catena di sink prima che il messaggio venga serializzato e trasportato.

Proprietà

NextChannelSink

Ottiene il sink di canale del server successivo nella catena di sink del server.

Properties

Ottiene un dizionario tramite il quale è possibile accedere alle proprietà sul sink.

(Ereditato da IChannelSinkBase)

Metodi

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

Richiede al sink corrente l'elaborazione della risposta da una chiamata di metodo inviata in modo asincrono.

GetResponseStream(IServerResponseChannelSinkStack, Object, IMessage, ITransportHeaders)

Restituisce l'oggetto Stream su cui dovrà essere serializzato il messaggio di risposta fornito.

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

Richiede l'elaborazione di messaggi da parte del sink corrente.

Si applica a