Share via


TcpServerChannel Classe

Definizione

Implementa un canale server per chiamate remote che utilizza il protocollo TCP per la trasmissione dei 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 a metodi da questa classe con dati non attendibili costituisce 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. Tutti 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). Per un elenco di queste proprietà di configurazione, vedere Proprietà di configurazione canale e formattatore.

Costruttori

TcpServerChannel(IDictionary, IServerChannelSinkProvider)

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

TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection)

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

TcpServerChannel(Int32)

Inizializza una nuova istanza della classe TcpServerChannel che è in attesa sulla porta specificata.

TcpServerChannel(String, Int32)

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

TcpServerChannel(String, Int32, IServerChannelSinkProvider)

Inizializza una nuova istanza della classe TcpServerChannel con il nome indicato, che è in attesa sulla porta specificata e utilizza il sink specificato.

Proprietà

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

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 l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
GetUrlsForUri(String)

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

MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
Parse(String, String)

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

StartListening(Object)

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

StopListening(Object)

Indica al canale corrente di interrompere l'attesa di richieste.

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a