HttpChannel Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Implémente un canal client pour les appels distants qui utilisent le protocole HTTP pour transmettre 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 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 uniquement avec des données approuvées. Pour plus d’informations, consultez Valider toutes les entrées.
Les canaux transportent les messages entre les limites de communication à distance (par exemple, entre les ordinateurs ou les 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 associé des propriétés de configuration 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).
Constructeurs
| Nom | Description |
|---|---|
| HttpChannel() |
Initialise une nouvelle instance de la classe HttpChannel. |
| HttpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider) |
Initialise une nouvelle instance de la HttpChannel classe avec les propriétés et récepteurs de configuration spécifiés. |
| HttpChannel(Int32) |
Initialise une nouvelle instance de la HttpChannel classe avec un canal de serveur qui écoute sur le port spécifié. |
Champs
| Nom | Description |
|---|---|
| SinksWithProperties |
Indique le récepteur de canal supérieur dans la pile du récepteur de canal. (Hérité de BaseChannelWithProperties) |
Propriétés
| Nom | Description |
|---|---|
| ChannelData |
Obtient les données spécifiques au canal. |
| ChannelName |
Obtient le nom du canal actuel. |
| ChannelPriority |
Obtient la priorité du canal actuel. |
| ChannelScheme |
Obtient le type d’écouteur à connecter (par exemple, « http »). |
| ChannelSinkChain |
Obtient la chaîne de récepteur de canal utilisée par le canal actuel. |
| Count |
Obtient le nombre de propriétés associées à l’objet de canal. (Hérité de BaseChannelObjectWithProperties) |
| IsFixedSize |
Obtient une valeur qui indique si le nombre de propriétés pouvant être entrées dans l’objet de canal est fixe. (Hérité de BaseChannelObjectWithProperties) |
| IsReadOnly |
Obtient une valeur qui indique si la collection de propriétés dans l’objet canal est en lecture seule. (Hérité de BaseChannelObjectWithProperties) |
| IsSecured |
Obtient ou définit une valeur booléenne qui indique si le canal actuel est sécurisé. |
| IsSynchronized |
Obtient une valeur qui indique si le dictionnaire des 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 une ICollection des clés auxquelles les propriétés du canal sont associées. |
| Properties |
Obtient une IDictionary des propriétés de canal associées au canal actuel. |
| SyncRoot |
Obtient un objet utilisé pour synchroniser l’accès BaseChannelObjectWithPropertiesau . (Hérité de BaseChannelObjectWithProperties) |
| Values |
Obtient une ICollection des valeurs des propriétés associées à l’objet de canal. (Hérité de BaseChannelObjectWithProperties) |
| WantsToListen |
Obtient une valeur booléenne qui indique si l’instance actuelle souhaite être connectée au service d’écouteur extérieur. |
Méthodes
| Nom | Description |
|---|---|
| Add(Object, Object) |
Lève un NotSupportedException. (Hérité de BaseChannelObjectWithProperties) |
| AddHookChannelUri(String) |
Ajoute un URI sur lequel le hook de canal doit écouter. |
| Clear() |
Lève un NotSupportedException. (Hérité de BaseChannelObjectWithProperties) |
| Contains(Object) |
Retourne une valeur qui indique si l’objet 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 des messages à l’URL ou à l’objet de données de canal spécifié. |
| Equals(Object) |
Détermine si l'objet spécifié est identique à l'objet actuel. (Hérité de Object) |
| GetEnumerator() |
Retourne une IDictionaryEnumerator valeur qui énumère toutes les propriétés associées à l’objet de canal. (Hérité de BaseChannelObjectWithProperties) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| GetUrlsForUri(String) |
Retourne un tableau de toutes les URL d’un objet avec l’URI spécifié, hébergé sur le fichier actif HttpChannel. |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| Parse(String, String) |
Extrait l’URI du canal et l’URI d’objet connu à distance à partir de l’URL spécifiée. |
| Remove(Object) |
Lève un NotSupportedException. (Hérité de BaseChannelObjectWithProperties) |
| StartListening(Object) |
Indique au canal actuel de commencer à écouter les demandes. |
| StopListening(Object) |
Indique au canal actuel d’arrêter l’écoute des requêtes. |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
Implémentations d’interfaces explicites
| Nom | Description |
|---|---|
| IEnumerable.GetEnumerator() |
Retourne une IEnumerator valeur qui énumère toutes les propriétés associées à l’objet de canal. (Hérité de BaseChannelObjectWithProperties) |
Méthodes d’extension
| Nom | Description |
|---|---|
| AsParallel(IEnumerable) |
Active la parallélisation d’une requête. |
| AsQueryable(IEnumerable) |
Convertit un IEnumerable en IQueryable. |
| Cast<TResult>(IEnumerable) |
Convertit les éléments d’un IEnumerable en type spécifié. |
| OfType<TResult>(IEnumerable) |
Filtre les éléments d’une IEnumerable en fonction d’un type spécifié. |