TcpClientChannel Classe

Définition

Pour les appels distants, implémente un canal client qui utilise le protocole TCP pour émettre des messages.

public ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSender
public ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSender
public class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type TcpClientChannel = class
    interface IChannelSender
    interface IChannel
type TcpClientChannel = class
    interface IChannelSender
    interface IChannel
    interface ISecurableChannel
Public Class TcpClientChannel
Implements IChannelSender
Public Class TcpClientChannel
Implements IChannelSender, ISecurableChannel
Héritage
TcpClientChannel
Implémente

Exemples

L’exemple de code suivant montre l’utilisation de la TcpClientChannel classe pour appeler un type distant.

#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 client channel.
   TcpClientChannel^ clientChannel = gcnew TcpClientChannel;
   ChannelServices::RegisterChannel( clientChannel );
   
   // Show the name and priority of the channel.
   Console::WriteLine( "Channel Name: {0}", clientChannel->ChannelName );
   Console::WriteLine( "Channel Priority: {0}", clientChannel->ChannelPriority );
   
   // Obtain a proxy for a remote object.
   RemotingConfiguration::RegisterWellKnownClientType( Remotable::typeid, "tcp://localhost:9090/Remotable.rem" );
   
   // Call a method on the object.
   Remotable ^ remoteObject = gcnew Remotable;
   Console::WriteLine( remoteObject->GetCount() );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Client
{
    public static void Main()
    {

        // Set up a client channel.
        TcpClientChannel clientChannel = new TcpClientChannel();
        ChannelServices.RegisterChannel(clientChannel);

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

        // Obtain a proxy for a remote object.
        RemotingConfiguration.RegisterWellKnownClientType(
            typeof(Remotable), "tcp://localhost:9090/Remotable.rem"
        );

        // Call a method on the object.
        Remotable remoteObject = new Remotable();
        Console.WriteLine( remoteObject.GetCount() );
    }
}

Le type distant appelé dans l’exemple ci-dessus est défini par le code suivant.

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

Remarques

Important

L’appel de méthodes de cette classe avec des données non approuvées est un risque de sécurité. Appelez les méthodes de cette classe avec des données approuvées uniquement. Pour plus d’informations, consultez Valider toutes les entrées.

Les canaux transportent les messages au-delà des limites de communication à distance (par exemple, les ordinateurs ou les domaines d’application). La TcpClientChannel classe transporte les messages à l’aide du protocole TCP.

Les canaux sont utilisés par l’infrastructure de communication à distance .NET Framework pour transporter les appels distants. Lorsqu’un client effectue un appel à un objet distant, l’appel est sérialisé dans un message envoyé par un canal client et reçu par un canal serveur. Il est ensuite désérialisé et traité. Toutes les valeurs retournées sont transmises par le canal serveur et reçues par le canal client.

Pour effectuer un traitement supplémentaire des messages côté client, vous pouvez spécifier une implémentation de l’interface IClientChannelSinkProvider via laquelle tous les messages traités par le TcpClientChannel sont passés.

Par défaut, la TcpClientChannel classe utilise un formateur binaire pour sérialiser tous les messages.

Un TcpClientChannel objet a des propriétés de configuration associées qui peuvent être définies au moment de l’exécution dans un fichier de configuration (en appelant la méthode statique RemotingConfiguration.Configure ) ou par programmation (en passant une IDictionary collection au TcpClientChannel constructeur). Pour obtenir la liste de ces propriétés de configuration, consultez la documentation relative à TcpClientChannel.

Constructeurs

TcpClientChannel()

Initialise une nouvelle instance de la classe TcpClientChannel.

TcpClientChannel(IDictionary, IClientChannelSinkProvider)

Initialise une nouvelle instance de la classe TcpClientChannel avec les propriétés de configuration et le récepteur spécifiés.

TcpClientChannel(String, IClientChannelSinkProvider)

Initialise une nouvelle instance de la classe TcpClientChannel avec le nom et le récepteur spécifiés.

Propriétés

ChannelName

Obtient le nom du canal en cours.

ChannelPriority

Obtient la priorité du canal actuel.

IsSecured

Obtient ou définit une valeur Boolean qui indique si le canal actuel est sécurisé.

Méthodes

CreateMessageSink(String, Object, String)

Retourne un récepteur de messages de canal qui remet les messages à l'URL ou à l'objet de données de canal spécifié.

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
Parse(String, String)

Extrait l'URI du canal et de l'objet connu distant à partir de l'URL spécifiée.

ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à