HttpServerChannel Classe

Definizione

Implementa un canale server per le chiamate remote che usano il protocollo HTTP per trasmettere messaggi.

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
Ereditarietà
Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato come usare un HttpServerChannel oggetto per configurare un server di comunicazione remota e il relativo client. L'esempio contiene tre parti:

  • Un server

  • Un client

  • Oggetto remoto utilizzato dal server e dal client

Nell'esempio di codice seguente viene illustrato un server.

#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.");
    }
}

Nell'esempio di codice seguente viene illustrato un client per questo server.

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

Nell'esempio di codice seguente viene illustrato l'oggetto remoto usato dal server e dal 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);
    }
}

Commenti

I canali trasportano i messaggi attraverso i limiti remoti, ad esempio tra computer nei domini applicazione. La HttpServerChannel classe trasporta i messaggi usando il protocollo HTTP.

I canali vengono usati dall'infrastruttura remota di .NET Framework per il trasporto di chiamate remote. Quando un client effettua una chiamata a un oggetto remoto, la chiamata viene serializzata in un messaggio inviato da un canale client e ricevuto da un canale server. Viene quindi deserializzato ed elaborato. I valori restituiti vengono trasmessi dal canale del server e ricevuti dal canale client.

Per eseguire un'ulteriore elaborazione dei messaggi sul lato server, è possibile specificare un'implementazione dell'oggetto IServerChannelSinkProvider tramite il quale vengono passati tutti i messaggi elaborati da HttpServerChannel .

HttpServerChannel accetta messaggi serializzati in formato binario o SOAP.

Un HttpServerChannel oggetto ha associato proprietà di configurazione che possono essere impostate in fase di esecuzione in un file di configurazione (richiamando il metodo statico RemotingConfiguration.Configure ) o a livello di codice (passando una IDictionary raccolta al HttpServerChannel costruttore). Per un elenco di queste proprietà di configurazione, vedere la documentazione per HttpServerChannel.

Costruttori

Nome Descrizione
HttpServerChannel()

Inizializza una nuova istanza della classe HttpServerChannel.

HttpServerChannel(IDictionary, IServerChannelSinkProvider)

Inizializza una nuova istanza della HttpServerChannel classe con le proprietà e il sink del canale specificati.

HttpServerChannel(Int32)

Inizializza una nuova istanza della HttpServerChannel classe in ascolto sulla porta specificata.

HttpServerChannel(String, Int32, IServerChannelSinkProvider)

Inizializza una nuova istanza della HttpServerChannel classe nella porta specificata con il nome specificato, che rimane in ascolto sulla porta specificata e usa il sink specificato.

HttpServerChannel(String, Int32)

Inizializza una nuova istanza della HttpServerChannel classe con il nome specificato e in ascolto sulla porta specificata.

Campi

Nome Descrizione
SinksWithProperties

Indica il sink del canale superiore nello stack di sink del canale.

(Ereditato da BaseChannelWithProperties)

Proprietà

Nome Descrizione
ChannelData

Ottiene dati specifici del canale.

ChannelName

Ottiene il nome del canale corrente.

ChannelPriority

Ottiene la priorità del canale corrente.

ChannelScheme

Ottiene il tipo di listener in cui eseguire l'hook, ad esempio "http".

ChannelSinkChain

Ottiene la catena di sink del canale usata dal canale corrente.

Count

Ottiene il numero di proprietà associate all'oggetto canale.

(Ereditato da BaseChannelObjectWithProperties)
IsFixedSize

Ottiene un valore che indica se il numero di proprietà che è possibile immettere nell'oggetto canale è fisso.

(Ereditato da BaseChannelObjectWithProperties)
IsReadOnly

Ottiene un valore che indica se la raccolta di proprietà nell'oggetto canale è di sola lettura.

(Ereditato da BaseChannelObjectWithProperties)
IsSynchronized

Ottiene un valore che indica se il dizionario delle proprietà dell'oggetto canale è sincronizzato.

(Ereditato da BaseChannelObjectWithProperties)
Item[Object]

Restituisce la proprietà del canale specificata.

Keys

Ottiene un ICollection di chiavi a cui sono associate le proprietà del canale.

Properties

Ottiene un IDictionary oggetto delle proprietà del canale associate all'oggetto canale corrente.

(Ereditato da BaseChannelWithProperties)
SyncRoot

Ottiene un oggetto utilizzato per sincronizzare l'accesso all'oggetto BaseChannelObjectWithProperties.

(Ereditato da BaseChannelObjectWithProperties)
Values

Ottiene un ICollection oggetto dei valori delle proprietà associate all'oggetto canale.

(Ereditato da BaseChannelObjectWithProperties)
WantsToListen

Ottiene un valore booleano che indica se IChannelReceiverHook si vuole associare al servizio listener esterno.

Metodi

Nome Descrizione
Add(Object, Object)

Genera un oggetto NotSupportedException.

(Ereditato da BaseChannelObjectWithProperties)
AddHookChannelUri(String)

Aggiunge un URI in cui l'hook del canale deve essere in ascolto.

Clear()

Genera un oggetto NotSupportedException.

(Ereditato da BaseChannelObjectWithProperties)
Contains(Object)

Restituisce un valore che indica se l'oggetto canale contiene una proprietà associata alla chiave specificata.

(Ereditato da BaseChannelObjectWithProperties)
CopyTo(Array, Int32)

Genera un oggetto NotSupportedException.

(Ereditato da BaseChannelObjectWithProperties)
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetChannelUri()

Restituisce l'URI del canale corrente.

GetEnumerator()

Restituisce un oggetto IDictionaryEnumerator che enumera tutte le proprietà associate all'oggetto canale.

(Ereditato da BaseChannelObjectWithProperties)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
GetUrlsForUri(String)

Restituisce una matrice di tutti gli URL per un oggetto con l'URI specificato, ospitato nell'oggetto corrente HttpChannel.

MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
Parse(String, String)

Estrae l'URI del canale e l'URI dell'oggetto noto remoto dall'URL specificato.

Remove(Object)

Genera un oggetto NotSupportedException.

(Ereditato da BaseChannelObjectWithProperties)
StartListening(Object)

Indica al canale corrente di avviare l'ascolto delle richieste.

StopListening(Object)

Indica al canale corrente di interrompere l'ascolto delle richieste.

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

Nome Descrizione
IEnumerable.GetEnumerator()

Restituisce un oggetto IEnumerator che enumera tutte le proprietà associate all'oggetto canale.

(Ereditato da BaseChannelObjectWithProperties)

Metodi di estensione

Nome Descrizione
AsParallel(IEnumerable)

Abilita la parallelizzazione di una query.

AsQueryable(IEnumerable)

Converte un IEnumerable in un IQueryable.

Cast<TResult>(IEnumerable)

Esegue il cast degli elementi di un IEnumerable al tipo specificato.

OfType<TResult>(IEnumerable)

Filtra gli elementi di un IEnumerable in base a un tipo specificato.

Si applica a