HttpChannel Klasa
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Implementuje kanał klienta dla wywołań zdalnych, które używają protokołu HTTP do przesyłania komunikatów.
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
- Dziedziczenie
- Implementuje
Przykłady
W poniższym przykładzie kodu pokazano, jak skonfigurować serwer komunikacji zdalnie i jego klienta za pomocą elementu a HttpClientChannel . Przykład zawiera trzy części:
Serwer
Klient
Obiekt zdalny używany przez serwer i klienta
Poniższy przykład kodu przedstawia serwer.
#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.");
}
}
Poniższy przykład kodu przedstawia klienta dla tego serwera.
#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());
}
}
Poniższy przykład kodu przedstawia obiekt zdalny używany przez serwer i klienta.
#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);
}
}
Uwagi
Ważna
Wywoływanie metod z tej klasy z niezaufanymi danymi jest zagrożeniem bezpieczeństwa. Wywołaj metody z tej klasy tylko z zaufanymi danymi. Aby uzyskać więcej informacji, zobacz Validate All Inputs.
Kanały transportują komunikaty przez granice komunikacji przychodzącej (na przykład między komputerami lub domenami aplikacji). Klasa HttpChannel transportuje komunikaty przy użyciu protokołu HTTP.
Kanały są używane przez infrastrukturę komunikacji zdalnej platformy .NET Framework do transportu połączeń zdalnych. Gdy klient wykonuje wywołanie obiektu zdalnego, wywołanie jest serializowane do komunikatu wysyłanego przez kanał klienta i odbieranego przez kanał serwera. Następnie jest deserializowany i przetwarzany. Wszystkie zwrócone wartości są przesyłane przez kanał serwera i odbierane przez kanał klienta.
Obiekt HttpChannel ma skojarzone właściwości konfiguracji, które można ustawić w czasie wykonywania w pliku konfiguracji (wywołując metodę statyczną RemotingConfiguration.Configure ) lub programowo (przekazując IDictionary kolekcję do konstruktora HttpChannel ).
Konstruktory
| Nazwa | Opis |
|---|---|
| HttpChannel() |
Inicjuje nowe wystąpienie klasy HttpChannel. |
| HttpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider) |
Inicjuje HttpChannel nowe wystąpienie klasy z określonymi właściwościami konfiguracji i ujściami. |
| HttpChannel(Int32) |
Inicjuje nowe wystąpienie HttpChannel klasy za pomocą kanału serwera, który nasłuchuje na określonym porcie. |
Pola
| Nazwa | Opis |
|---|---|
| SinksWithProperties |
Wskazuje ujście kanału górnego w stosie ujścia kanału. (Odziedziczone po BaseChannelWithProperties) |
Właściwości
| Nazwa | Opis |
|---|---|
| ChannelData |
Pobiera dane specyficzne dla kanału. |
| ChannelName |
Pobiera nazwę bieżącego kanału. |
| ChannelPriority |
Pobiera priorytet bieżącego kanału. |
| ChannelScheme |
Pobiera typ odbiornika do przyłączenia (na przykład "http"). |
| ChannelSinkChain |
Pobiera łańcuch ujścia kanału używany przez bieżący kanał. |
| Count |
Pobiera liczbę właściwości skojarzonych z obiektem kanału. (Odziedziczone po BaseChannelObjectWithProperties) |
| IsFixedSize |
Pobiera wartość wskazującą, czy liczba właściwości, które można wprowadzić do obiektu kanału, jest stała. (Odziedziczone po BaseChannelObjectWithProperties) |
| IsReadOnly |
Pobiera wartość wskazującą, czy kolekcja właściwości w obiekcie kanału jest tylko do odczytu. (Odziedziczone po BaseChannelObjectWithProperties) |
| IsSecured |
Pobiera lub ustawia wartość logiczną wskazującą, czy bieżący kanał jest bezpieczny. |
| IsSynchronized |
Pobiera wartość wskazującą, czy słownik właściwości obiektu kanału jest synchronizowany. (Odziedziczone po BaseChannelObjectWithProperties) |
| Item[Object] |
Zwraca określoną właściwość kanału. |
| Keys |
Pobiera klucze ICollection , z którymi są skojarzone właściwości kanału. |
| Properties |
Pobiera właściwości IDictionary kanału skojarzone z bieżącym kanałem. |
| SyncRoot |
Pobiera obiekt używany do synchronizowania dostępu do obiektu BaseChannelObjectWithProperties. (Odziedziczone po BaseChannelObjectWithProperties) |
| Values |
Pobiera wartości ICollection właściwości skojarzonych z obiektem kanału. (Odziedziczone po BaseChannelObjectWithProperties) |
| WantsToListen |
Pobiera wartość logiczną wskazującą, czy bieżące wystąpienie chce zostać podłączone do zewnętrznej usługi odbiornika. |
Metody
| Nazwa | Opis |
|---|---|
| Add(Object, Object) |
Zgłasza element NotSupportedException. (Odziedziczone po BaseChannelObjectWithProperties) |
| AddHookChannelUri(String) |
Dodaje identyfikator URI, na którym punkt zaczepienia kanału powinien nasłuchiwać. |
| Clear() |
Zgłasza element NotSupportedException. (Odziedziczone po BaseChannelObjectWithProperties) |
| Contains(Object) |
Zwraca wartość wskazującą, czy obiekt kanału zawiera właściwość skojarzona z określonym kluczem. (Odziedziczone po BaseChannelObjectWithProperties) |
| CopyTo(Array, Int32) |
Zgłasza element NotSupportedException. (Odziedziczone po BaseChannelObjectWithProperties) |
| CreateMessageSink(String, Object, String) |
Zwraca ujście komunikatu kanału, który dostarcza komunikaty do określonego adresu URL lub obiektu danych kanału. |
| Equals(Object) |
Określa, czy dany obiekt jest taki sam, jak bieżący obiekt. (Odziedziczone po Object) |
| GetEnumerator() |
Zwraca wartość IDictionaryEnumerator , która wylicza wszystkie właściwości skojarzone z obiektem kanału. (Odziedziczone po BaseChannelObjectWithProperties) |
| GetHashCode() |
Służy jako domyślna funkcja skrótu. (Odziedziczone po Object) |
| GetType() |
Pobiera Type bieżącego wystąpienia. (Odziedziczone po Object) |
| GetUrlsForUri(String) |
Zwraca tablicę wszystkich adresów URL obiektu z określonym identyfikatorem URI hostowanym w bieżącym obiekcie HttpChannel. |
| MemberwiseClone() |
Tworzy płytkią kopię bieżącego Object. (Odziedziczone po Object) |
| Parse(String, String) |
Wyodrębnia identyfikator URI kanału i zdalnego dobrze znanego identyfikatora URI obiektu z określonego adresu URL. |
| Remove(Object) |
Zgłasza element NotSupportedException. (Odziedziczone po BaseChannelObjectWithProperties) |
| StartListening(Object) |
Instruuje bieżący kanał, aby zaczął nasłuchiwać żądań. |
| StopListening(Object) |
Instruuje bieżący kanał, aby zatrzymał nasłuchiwanie żądań. |
| ToString() |
Zwraca ciąg reprezentujący bieżący obiekt. (Odziedziczone po Object) |
Jawne implementacje interfejsu
| Nazwa | Opis |
|---|---|
| IEnumerable.GetEnumerator() |
Zwraca wartość IEnumerator , która wylicza wszystkie właściwości skojarzone z obiektem kanału. (Odziedziczone po BaseChannelObjectWithProperties) |
Metody rozszerzania
| Nazwa | Opis |
|---|---|
| AsParallel(IEnumerable) |
Umożliwia równoległość zapytania. |
| AsQueryable(IEnumerable) |
Konwertuje IEnumerable na IQueryable. |
| Cast<TResult>(IEnumerable) |
Rzutuje elementy IEnumerable do określonego typu. |
| OfType<TResult>(IEnumerable) |
Filtruje elementy IEnumerable na podstawie określonego typu. |