HttpServerChannel 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 de serveur pour les appels distants qui utilisent le protocole HTTP pour transmettre des messages.
public ref class HttpServerChannel : System::Runtime::Remoting::Channels::BaseChannelWithProperties, System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::IChannelReceiverHook
public class HttpServerChannel : System.Runtime.Remoting.Channels.BaseChannelWithProperties, System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.IChannelReceiverHook
type HttpServerChannel = class
inherit BaseChannelWithProperties
interface IChannelReceiver
interface IChannel
interface IChannelReceiverHook
Public Class HttpServerChannel
Inherits BaseChannelWithProperties
Implements IChannelReceiver, IChannelReceiverHook
- Héritage
- Implémente
Exemples
L’exemple de code suivant montre comment utiliser un HttpServerChannel objet 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;
int main()
{
// Create the server channel.
HttpServerChannel^ serverChannel = gcnew HttpServerChannel( 9090 );
// Register the server channel.
ChannelServices::RegisterChannel( serverChannel );
// Display the channel's scheme.
Console::WriteLine( L"The channel scheme is {0}.", serverChannel->ChannelScheme );
// Display the channel's URI.
Console::WriteLine( L"The channel URI is {0}.", serverChannel->GetChannelUri() );
// Expose an object for remote calls.
RemotingConfiguration::RegisterWellKnownServiceType(
RemoteObject::typeid, L"RemoteObject.rem", WellKnownObjectMode::Singleton );
// Get the channel's sink chain.
IServerChannelSink^ sinkChain = serverChannel->ChannelSinkChain;
Console::WriteLine( L"The type of the server channel's sink chain is {0}.", sinkChain->GetType() );
// See if the channel wants to listen.
bool wantsToListen = serverChannel->WantsToListen;
Console::WriteLine( L"The value of WantsToListen is {0}.", wantsToListen );
// Parse the channel's URI.
array<String^>^ urls = serverChannel->GetUrlsForUri( L"RemoteObject.rem" );
if ( urls->Length > 0 )
{
String^ objectUrl = urls[ 0 ];
String^ objectUri;
String^ channelUri = serverChannel->Parse( objectUrl, objectUri );
Console::WriteLine( L"The object URI is {0}.", objectUri );
Console::WriteLine( L"The channel URI is {0}.", channelUri );
Console::WriteLine( L"The object URL is {0}.", objectUrl );
}
// 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);
// Display the channel's scheme.
Console.WriteLine("The channel scheme is {0}.",
serverChannel.ChannelScheme);
// Display the channel's URI.
Console.WriteLine("The channel URI is {0}.",
serverChannel.GetChannelUri());
// Expose an object for remote calls.
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(RemoteObject), "RemoteObject.rem",
WellKnownObjectMode.Singleton);
// Get the channel's sink chain.
IServerChannelSink sinkChain = serverChannel.ChannelSinkChain;
Console.WriteLine(
"The type of the server channel's sink chain is {0}.",
sinkChain.GetType().ToString());
// See if the channel wants to listen.
bool wantsToListen = serverChannel.WantsToListen;
Console.WriteLine(
"The value of WantsToListen is {0}.",
wantsToListen);
// Parse the channel's URI.
string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
if (urls.Length > 0)
{
string objectUrl = urls[0];
string objectUri;
string channelUri =
serverChannel.Parse(objectUrl, out objectUri);
Console.WriteLine("The object URI is {0}.", objectUri);
Console.WriteLine("The channel URI is {0}.", channelUri);
Console.WriteLine("The object URL is {0}.", objectUrl);
}
// 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^ channel = gcnew HttpClientChannel;
// Register the channel.
ChannelServices::RegisterChannel( channel );
// Register as client for remote object.
WellKnownClientTypeEntry^ remoteType = gcnew WellKnownClientTypeEntry(
RemoteObject::typeid,L"http://localhost:9090/RemoteObject.rem" );
RemotingConfiguration::RegisterWellKnownClientType( remoteType );
// 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 channel = new HttpClientChannel();
// Register the channel.
ChannelServices.RegisterChannel(channel);
// Register as client for remote object.
WellKnownClientTypeEntry remoteType = new WellKnownClientTypeEntry(
typeof(RemoteObject),"http://localhost:9090/RemoteObject.rem");
RemotingConfiguration.RegisterWellKnownClientType(remoteType);
// 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 namespace System;
using namespace System::Runtime::Remoting;
// Remote object.
public ref class RemoteObject: public MarshalByRefObject
{
private:
static int callCount = 0;
public:
int GetCount()
{
callCount++;
return (callCount);
}
};
using System;
using System.Runtime.Remoting;
// Remote object.
public class RemoteObject : MarshalByRefObject
{
private int callCount = 0;
public int GetCount()
{
callCount++;
return(callCount);
}
}
Remarques
Les canaux transportent les messages entre les limites de communication à distance (par exemple, entre les ordinateurs sur les domaines d’application). La HttpServerChannel 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.
Pour effectuer un traitement supplémentaire des messages côté serveur, vous pouvez spécifier une implémentation du IServerChannelSinkProvider processus par lequel tous les messages traités par le HttpServerChannel serveur sont transmis.
Les HttpServerChannel messages acceptent la sérialisation au format binaire ou SOAP.
Un HttpServerChannel 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 HttpServerChannel constructeur). Pour obtenir la liste de ces propriétés de configuration, consultez la documentation pour HttpServerChannel.
Constructeurs
| Nom | Description |
|---|---|
| HttpServerChannel() |
Initialise une nouvelle instance de la classe HttpServerChannel. |
| HttpServerChannel(IDictionary, IServerChannelSinkProvider) |
Initialise une nouvelle instance de la HttpServerChannel classe avec les propriétés et le récepteur de canal spécifiés. |
| HttpServerChannel(Int32) |
Initialise une nouvelle instance de la HttpServerChannel classe qui écoute sur le port spécifié. |
| HttpServerChannel(String, Int32, IServerChannelSinkProvider) |
Initialise une nouvelle instance de la HttpServerChannel classe au niveau du port spécifié avec le nom donné, qui écoute sur le port spécifié et utilise le récepteur spécifié. |
| HttpServerChannel(String, Int32) |
Initialise une nouvelle instance de la HttpServerChannel classe avec le nom donné et 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 des 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) |
| 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 dont les propriétés de canal sont associées. |
| Properties |
Obtient une IDictionary des propriétés de canal associées à l’objet canal actuel. (Hérité de BaseChannelWithProperties) |
| 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 IChannelReceiverHook les souhaits doivent être connectés au service d’écouteur externe. |
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) |
| Equals(Object) |
Détermine si l'objet spécifié est identique à l'objet actuel. (Hérité de Object) |
| GetChannelUri() |
Retourne l’URI du canal actuel. |
| 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é. |