HttpChannel Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Implementa un canale client per le chiamate remote che usano il protocollo HTTP per trasmettere messaggi.
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
- Ereditarietà
- Implementazioni
Esempio
Nell'esempio di codice seguente viene illustrato come usare un HttpClientChannel 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;
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.");
}
}
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^ 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());
}
}
Nell'esempio di codice seguente viene illustrato l'oggetto remoto usato dal server e dal 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);
}
}
Commenti
Importante
La chiamata di metodi da questa classe con dati non attendibili è un rischio per la sicurezza. Chiamare i metodi da questa classe solo con dati attendibili. Per altre informazioni, vedere Convalidare tutti gli input.
I canali trasportano i messaggi attraverso i limiti remoti ,ad esempio tra computer o domini applicazione. La HttpChannel 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.
Un HttpChannel 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 HttpChannel costruttore).
Costruttori
| Nome | Descrizione |
|---|---|
| HttpChannel() |
Inizializza una nuova istanza della classe HttpChannel. |
| HttpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider) |
Inizializza una nuova istanza della HttpChannel classe con le proprietà e i sink di configurazione specificati. |
| HttpChannel(Int32) |
Inizializza una nuova istanza della HttpChannel classe con un canale server 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 i 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) |
| IsSecured |
Ottiene o imposta un valore booleano che indica se il canale corrente è protetto. |
| 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 oggetto di chiavi a cui sono associate le proprietà del canale. |
| Properties |
Ottiene una IDictionary delle proprietà del canale associate al canale corrente. |
| 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 l'istanza corrente vuole essere agganciata al servizio listener esterno. |
Metodi
| Nome | Descrizione |
|---|---|
| Add(Object, Object) |
Genera un oggetto NotSupportedException. (Ereditato da BaseChannelObjectWithProperties) |
| AddHookChannelUri(String) |
Aggiunge un URI in cui deve essere in ascolto l'hook del canale. |
| 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) |
| CreateMessageSink(String, Object, String) |
Restituisce un sink di messaggi del canale che recapita messaggi all'URL o all'oggetto dati del canale specificato. |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| 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. |