Share via


HttpChannel Classe

Définition

Implémente un canal client pour les appels distants qui utilise le protocole HTTP pour émettre des messages.

public ref class HttpChannel : System::Runtime::Remoting::Channels::BaseChannelWithProperties, System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::IChannelReceiverHook, System::Runtime::Remoting::Channels::IChannelSender
public ref class HttpChannel : System::Runtime::Remoting::Channels::BaseChannelWithProperties, System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::IChannelReceiverHook, System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class HttpChannel : System.Runtime.Remoting.Channels.BaseChannelWithProperties, System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.IChannelReceiverHook, System.Runtime.Remoting.Channels.IChannelSender
public class HttpChannel : System.Runtime.Remoting.Channels.BaseChannelWithProperties, System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.IChannelReceiverHook, System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type HttpChannel = class
    inherit BaseChannelWithProperties
    interface IChannelReceiver
    interface IChannelSender
    interface IChannel
    interface IChannelReceiverHook
type HttpChannel = class
    inherit BaseChannelWithProperties
    interface IChannelReceiver
    interface IChannelSender
    interface IChannel
    interface IChannelReceiverHook
    interface ISecurableChannel
type HttpChannel = class
    inherit BaseChannelWithProperties
    interface IChannelReceiver
    interface IChannel
    interface IChannelSender
    interface IChannelReceiverHook
    interface ISecurableChannel
Public Class HttpChannel
Inherits BaseChannelWithProperties
Implements IChannelReceiver, IChannelReceiverHook, IChannelSender
Public Class HttpChannel
Inherits BaseChannelWithProperties
Implements IChannelReceiver, IChannelReceiverHook, IChannelSender, ISecurableChannel
Héritage
Implémente

Exemples

L’exemple de code suivant montre comment utiliser un HttpClientChannel pour configurer un serveur de communication à distance et son client. L’exemple contient trois parties :

  • Un serveur

  • Un client

  • Objet distant utilisé par le serveur et le client

L’exemple de code suivant montre un serveur.

#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;

void main()
{
   // Create the server channel.
   HttpServerChannel^ serverChannel = gcnew HttpServerChannel( 9090 );
   
   // Register the server channel.
   ChannelServices::RegisterChannel( serverChannel );
   
   // Expose an object for remote calls.
   RemotingConfiguration::RegisterWellKnownServiceType( RemoteObject::typeid, L"RemoteObject.rem", WellKnownObjectMode::Singleton );
   
   // Wait for the user prompt.
   Console::WriteLine( L"Press ENTER to exit the server." );
   Console::ReadLine();
   Console::WriteLine( L"The server is exiting." );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class Server
{
    public static void Main(string[] args)
    {
        // Create the server channel.
        HttpServerChannel serverChannel = new HttpServerChannel(9090);

        // Register the server channel.
        ChannelServices.RegisterChannel(serverChannel);

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

        // Wait for the user prompt.
        Console.WriteLine("Press ENTER to exit the server.");
        Console.ReadLine();
        Console.WriteLine("The server is exiting.");
    }
}

L’exemple de code suivant montre un client pour ce serveur.

#using <System.dll>
#using <System.Runtime.Remoting.dll>
#using "common.dll"

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Http;
void main()
{
   // Create the channel.
   HttpClientChannel^ clientChannel = gcnew HttpClientChannel;

   // Register the channel.
   ChannelServices::RegisterChannel( clientChannel );

   // Register as client for remote object.
   WellKnownClientTypeEntry^ remoteType = gcnew WellKnownClientTypeEntry( RemoteObject::typeid,L"http://localhost:9090/RemoteObject.rem" );
   RemotingConfiguration::RegisterWellKnownClientType( remoteType );

   // Create a message sink.
   String^ objectUri;
   System::Runtime::Remoting::Messaging::IMessageSink^ messageSink = clientChannel->CreateMessageSink( L"http://localhost:9090/RemoteObject.rem", nullptr,  objectUri );
   Console::WriteLine( L"The URI of the message sink is {0}.", objectUri );
   if ( messageSink != nullptr )
   {
      Console::WriteLine( L"The type of the message sink is {0}.", messageSink->GetType() );
   }

   // Display the channel's properties using Keys and Item.
   for each(String^ key in clientChannel->Keys)
   {
       Console::WriteLine("clientChannel[{0}] = <{1}>", key, clientChannel[key]);
   }

   // Parse the channel's URI.
   String^ objectUrl = L"http://localhost:9090/RemoteObject.rem";
   String^ channelUri = clientChannel->Parse( objectUrl,  objectUri );
   Console::WriteLine( L"The object URL is {0}.", objectUrl );
   Console::WriteLine( L"The object URI is {0}.", objectUri );
   Console::WriteLine( L"The channel URI is {0}.", channelUri );

   // Create an instance of the remote object.
   RemoteObject^ service = gcnew RemoteObject;
   
   // Invoke a method on the remote object.
   Console::WriteLine( L"The client is invoking the remote object." );
   Console::WriteLine( L"The remote object has been called {0} times.", service->GetCount() );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

public class Client
{
    public static void Main(string[] args)
    {
        // Create the channel.
        HttpClientChannel clientChannel = new HttpClientChannel();

        // Register the channel.
        ChannelServices.RegisterChannel(clientChannel);

        // Register as client for remote object.
        WellKnownClientTypeEntry remoteType =
            new WellKnownClientTypeEntry(typeof(RemoteObject),
            "http://localhost:9090/RemoteObject.rem");
        RemotingConfiguration.RegisterWellKnownClientType(remoteType);

        // Create a message sink.
        string objectUri;
        System.Runtime.Remoting.Messaging.IMessageSink messageSink =
            clientChannel.CreateMessageSink(
            "http://localhost:9090/RemoteObject.rem",
            null, out objectUri);
        Console.WriteLine(
            "The URI of the message sink is {0}.",
            objectUri);
        if (messageSink != null)
        {
            Console.WriteLine("The type of the message sink is {0}.",
                messageSink.GetType().ToString());
        }

        // Display the channel's properties using Keys and Item.
        foreach(string key in clientChannel.Keys)
        {
            Console.WriteLine(
                "clientChannel[{0}] = <{1}>",
                key, clientChannel[key]);
        }

        // Parse the channel's URI.
        string objectUrl = "http://localhost:9090/RemoteObject.rem";
        string channelUri = clientChannel.Parse(objectUrl, out objectUri);
        Console.WriteLine("The object URL is {0}.", objectUrl);
        Console.WriteLine("The object URI is {0}.", objectUri);
        Console.WriteLine("The channel URI is {0}.", channelUri);

        // Create an instance of the remote object.
        RemoteObject service = new RemoteObject();

        // Invoke a method on the remote object.
        Console.WriteLine("The client is invoking the remote object.");
        Console.WriteLine("The remote object has been called {0} times.",
            service.GetCount());
    }
}

L’exemple de code suivant montre l’objet distant utilisé par le serveur et le client.

#using <System.dll>
using namespace System;
using namespace System::Runtime::Remoting;

// Remote object.
public ref class RemoteObject: public MarshalByRefObject
{
private:
   static int callCount = 0;

public:
   int GetCount()
   {
      Console::WriteLine( L"GetCount was called." );
      callCount++;
      return (callCount);
   }

};
using System;
using System.Runtime.Remoting;

// Remote object.
public class RemoteObject : MarshalByRefObject
{
    private int callCount = 0;

    public int GetCount()
    {
        Console.WriteLine("GetCount was called.");
        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, entre des ordinateurs ou des domaines d’application). La HttpChannel classe transporte les messages à l’aide du protocole HTTP.

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.

Un HttpChannel 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 HttpChannel constructeur). Pour obtenir la liste de ces propriétés de configuration, consultez Propriétés de configuration du canal et du formateur.

Constructeurs

HttpChannel()

Initialise une nouvelle instance de la classe HttpChannel.

HttpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider)

Initialise une nouvelle instance de la classe HttpChannel avec les propriétés de configuration et les récepteurs spécifiés.

HttpChannel(Int32)

Initialise une nouvelle instance de la classe HttpChannel avec un canal serveur qui écoute sur le port spécifié.

Champs

SinksWithProperties

Indique le récepteur de canal supérieur dans une pile de récepteurs de canaux.

(Hérité de BaseChannelWithProperties)

Propriétés

ChannelData

Obtient les données spécifiques de canal.

ChannelName

Obtient le nom du canal en cours.

ChannelPriority

Obtient la priorité du canal actuel.

ChannelScheme

Obtient le type d'écouteur auquel se raccorder (par exemple, « http »).

ChannelSinkChain

Obtient la chaîne de récepteurs de canal utilisée par le canal en cours.

Count

Obtient le nombre de propriétés associées à l'objet de canal.

(Hérité de BaseChannelObjectWithProperties)
IsFixedSize

Obtient une valeur indiquant si le nombre de propriétés qui peuvent être entrées dans l'objet de canal est fixe.

(Hérité de BaseChannelObjectWithProperties)
IsReadOnly

Obtient une valeur indiquant si la collection de propriétés dans l'objet de canal est en lecture seule.

(Hérité de BaseChannelObjectWithProperties)
IsSecured

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

IsSynchronized

Obtient une valeur indiquant si le dictionnaire de propriétés d'objet de canal est synchronisé.

(Hérité de BaseChannelObjectWithProperties)
Item[Object]

Retourne la propriété de canal spécifiée.

Keys

Obtient un ICollection des clés auxquelles les propriétés du canal sont associées.

Properties

Obtient un IDictionary des propriétés de canal associées au canal en cours.

SyncRoot

Obtient un objet qui est utilisé pour synchroniser l'accès à BaseChannelObjectWithProperties.

(Hérité de BaseChannelObjectWithProperties)
Values

Obtient un ICollection des valeurs des propriétés associées à l'objet de canal.

(Hérité de BaseChannelObjectWithProperties)
WantsToListen

Obtient une valeur booléenne indiquant si l'instance actuelle doit être raccordée à l'écouteur externe.

Méthodes

Add(Object, Object)

Lève un NotSupportedException.

(Hérité de BaseChannelObjectWithProperties)
AddHookChannelUri(String)

Ajoute un URI que le raccordement du canal doit écouter.

Clear()

Lève un NotSupportedException.

(Hérité de BaseChannelObjectWithProperties)
Contains(Object)

Retourne une valeur indiquant si l'objet de canal contient une propriété associée à la clé spécifiée.

(Hérité de BaseChannelObjectWithProperties)
CopyTo(Array, Int32)

Lève un NotSupportedException.

(Hérité de BaseChannelObjectWithProperties)
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)
GetEnumerator()

Retourne un IDictionaryEnumerator qui énumère toutes les propriétés associées à l'objet de canal.

(Hérité de BaseChannelObjectWithProperties)
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)
GetUrlsForUri(String)

Retourne un tableau de toutes les URL d'un objet doté de l'URI spécifié qui sont hébergées sur HttpChannel en cours.

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.

Remove(Object)

Lève un NotSupportedException.

(Hérité de BaseChannelObjectWithProperties)
StartListening(Object)

Commande au canal en cours de démarrer l'écoute des demandes.

StopListening(Object)

Commande au canal en cours d'arrêter l'écoute des demandes.

ToString()

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

(Hérité de Object)

Implémentations d’interfaces explicites

IEnumerable.GetEnumerator()

Retourne un IEnumerator qui énumère toutes les propriétés associées à l'objet de canal.

(Hérité de BaseChannelObjectWithProperties)

Méthodes d’extension

Cast<TResult>(IEnumerable)

Effectue un cast des éléments d'un IEnumerable vers le type spécifié.

OfType<TResult>(IEnumerable)

Filtre les éléments d'un IEnumerable en fonction du type spécifié.

AsParallel(IEnumerable)

Active la parallélisation d'une requête.

AsQueryable(IEnumerable)

Convertit un IEnumerable en IQueryable.

S’applique à

Voir aussi