HttpServerChannel Classe

Définition

Implémente pour les appels distants un canal serveur qui utilise 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 au-delà des limites de communication à distance (par exemple, entre des ordinateurs sur des 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 de via IServerChannelSinkProvider laquelle tous les messages traités par le HttpServerChannel sont passés.

accepte les HttpServerChannel messages sérialisés au format binaire ou SOAP.

Un HttpServerChannel 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 HttpServerChannel constructeur). Pour obtenir la liste de ces propriétés de configuration, consultez la documentation relative à HttpServerChannel.

Constructeurs

HttpServerChannel()

Initialise une nouvelle instance de la classe HttpServerChannel.

HttpServerChannel(IDictionary, IServerChannelSinkProvider)

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

HttpServerChannel(Int32)

Initialise une nouvelle instance de la classe HttpServerChannel qui écoute sur le port spécifié.

HttpServerChannel(String, Int32)

Initialise une nouvelle instance de la classe HttpServerChannel portant le nom indiqué et à l'écoute sur le port spécifié.

HttpServerChannel(String, Int32, IServerChannelSinkProvider)

Initialise une nouvelle instance de la classe HttpServerChannel au port spécifié avec le nom donné, qui écoute sur le port spécifié et utilise le récepteur 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 au 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)
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 à l'objet de canal en cours.

(Hérité de BaseChannelWithProperties)
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 IChannelReceiverHook souhaite être raccordé à l'écouteur externe.

Méthodes

Add(Object, Object)

Lève un NotSupportedException.

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

Ajoute un URI que le raccordement de 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)
Equals(Object)

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

(Hérité de Object)
GetChannelUri()

Retourne l'URI du canal en cours.

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