Condividi tramite


TcpServerChannel Classe

Definizione

Implementa un canale server per le chiamate remote che usano il protocollo TCP per trasmettere messaggi.

public ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiver
public ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::ISecurableChannel
public class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiver
public class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.ISecurableChannel
type TcpServerChannel = class
    interface IChannelReceiver
    interface IChannel
type TcpServerChannel = class
    interface IChannelReceiver
    interface IChannel
    interface ISecurableChannel
Public Class TcpServerChannel
Implements IChannelReceiver
Public Class TcpServerChannel
Implements IChannelReceiver, ISecurableChannel
Ereditarietà
TcpServerChannel
Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato l'uso di un tipo remotable.

using namespace System;
using namespace System::Runtime::Remoting;

public ref class Remotable: public MarshalByRefObject
{
private:
   int callCount;

public:
   Remotable()
      : callCount( 0 )
   {}

   int GetCount()
   {
      callCount++;
      return (callCount);
   }
};
using System;
using System.Runtime.Remoting;

public class Remotable : MarshalByRefObject
{

    private int callCount = 0;

    public int GetCount()
    {
        callCount++;
        return(callCount);
    }
}

Nell'esempio di codice seguente viene illustrato l'uso della TcpServerChannel classe per esporre un tipo remotable.

#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <Remotable.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;

int main()
{
   // Set up a server channel.
   TcpServerChannel^ serverChannel = gcnew TcpServerChannel( 9090 );
   ChannelServices::RegisterChannel( serverChannel );

   // Expose an object for remote calls.
   RemotingConfiguration::RegisterWellKnownServiceType( Remotable::typeid, "Remotable.rem", WellKnownObjectMode::Singleton );

   // Show the name and priority of the channel.
   Console::WriteLine( "Channel Name: {0}", serverChannel->ChannelName );
   Console::WriteLine( "Channel Priority: {0}", serverChannel->ChannelPriority );

   // Show the URIs associated with the channel.
   ChannelDataStore^ data = dynamic_cast<ChannelDataStore^>(serverChannel->ChannelData);
   System::Collections::IEnumerator^ myEnum = data->ChannelUris->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      String^ uri = safe_cast<String^>(myEnum->Current);
      Console::WriteLine( uri );
   }

   // Wait for method calls.
   Console::WriteLine( "Listening..." );
   Console::ReadLine();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Server
{
    public static void Main()
    {

        // Set up a server channel.
        TcpServerChannel serverChannel = new TcpServerChannel(9090);
        ChannelServices.RegisterChannel(serverChannel);

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(Remotable), "Remotable.rem", WellKnownObjectMode.Singleton
        );

        // Show the name and priority of the channel.
        Console.WriteLine("Channel Name: {0}", serverChannel.ChannelName);
        Console.WriteLine("Channel Priority: {0}", serverChannel.ChannelPriority);

        // Show the URIs associated with the channel.
        ChannelDataStore data = (ChannelDataStore) serverChannel.ChannelData;
        foreach (string uri in data.ChannelUris)
        {
            Console.WriteLine(uri);
        }

        // Wait for method calls.
        Console.WriteLine("Listening...");
        Console.ReadLine();
    }
}

Commenti

Importante

La chiamata di metodi da questa classe con dati non attendibili è un rischio per la sicurezza. Chiamare i metodi da questa classe solo con dati attendibili. Per altre informazioni, vedere Convalidare tutti gli input.

I canali trasportano i messaggi attraverso i limiti remoti , ad esempio computer o domini applicazione. La TcpServerChannel classe trasporta i messaggi usando il protocollo TCP.

I canali vengono usati dall'infrastruttura remota di .NET Framework per il trasporto di chiamate remote. Quando un client effettua una chiamata a un oggetto remoto, la chiamata viene serializzata in un messaggio inviato da un canale client e ricevuto da un canale server. Viene quindi deserializzato ed elaborato. I valori restituiti vengono trasmessi dal canale del server e ricevuti dal canale client.

Per eseguire un'ulteriore elaborazione dei messaggi sul lato server, è possibile specificare un'implementazione dell'interfaccia IServerChannelSinkProvider tramite cui vengono passati tutti i messaggi elaborati dall'istanza TcpServerChannel .

L'istanza TcpServerChannel accetta messaggi serializzati in formato binario o SOAP.

Un TcpServerChannel oggetto ha associato proprietà di configurazione che possono essere impostate in fase di esecuzione in un file di configurazione (richiamando il metodo statico RemotingConfiguration.Configure ) o a livello di codice (passando una IDictionary raccolta al TcpServerChannel costruttore).

Costruttori

Nome Descrizione
TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection)

Inizializza una nuova istanza della TcpServerChannel classe con le proprietà del canale, il sink e il provider di autorizzazione specificati.

TcpServerChannel(IDictionary, IServerChannelSinkProvider)

Inizializza una nuova istanza della TcpServerChannel classe con le proprietà e il sink del canale specificati.

TcpServerChannel(Int32)

Inizializza una nuova istanza della TcpServerChannel classe in ascolto sulla porta specificata.

TcpServerChannel(String, Int32, IServerChannelSinkProvider)

Inizializza una nuova istanza della TcpServerChannel classe con il nome specificato, in ascolto sulla porta specificata e usa il sink specificato.

TcpServerChannel(String, Int32)

Inizializza una nuova istanza della TcpServerChannel classe con il nome specificato e in ascolto sulla porta specificata.

Proprietà

Nome Descrizione
ChannelData

Ottiene dati specifici del canale.

ChannelName

Ottiene il nome del canale corrente.

ChannelPriority

Ottiene la priorità del canale corrente.

IsSecured

Ottiene o imposta un valore booleano che indica se il canale corrente è protetto.

Metodi

Nome Descrizione
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetChannelUri()

Restituisce l'URI del canale corrente.

GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
GetUrlsForUri(String)

Restituisce una matrice di tutti gli URL per un oggetto con l'URI specificato, ospitato nell'istanza corrente TcpChannel .

MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
Parse(String, String)

Estrae l'URI del canale e l'URI dell'oggetto noto remoto dall'URL specificato.

StartListening(Object)

Indica al canale corrente di avviare l'ascolto su un canale dopo che il StopListening(Object) metodo è stato chiamato per interrompere l'ascolto sul canale.

StopListening(Object)

Indica al canale corrente di interrompere l'ascolto delle richieste.

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a