HttpChannel Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Implementuje klientský kanál pro vzdálená volání, která k přenosu zpráv používá protokol HTTP.
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
- Dědičnost
- Implementuje
Příklady
Následující příklad kódu ukazuje, jak použít HttpClientChannel k nastavení vzdálené komunikace serveru a jeho klienta. Příklad obsahuje tři části:
Server
Klient
Vzdálený objekt používaný serverem a klientem
Následující příklad kódu ukazuje 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.");
}
}
Následující příklad kódu ukazuje klienta pro tento 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());
}
}
Následující příklad kódu ukazuje vzdálený objekt používaný serverem a klientem.
#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);
}
}
Poznámky
Důležité
Volání metod z této třídy s nedůvěryhodnými daty představuje bezpečnostní riziko. Volejte metody z této třídy pouze s důvěryhodnými daty. Další informace naleznete v tématu Ověření všech vstupů.
Kanály přenášejí zprávy přes hranice vzdálené komunikace (například mezi počítači nebo doménami aplikace). Třída HttpChannel přenáší zprávy pomocí protokolu HTTP.
Kanály používají infrastruktura vzdálené komunikace .NET Framework k přenosu vzdálených volání. Když klient provede volání vzdáleného objektu, volání se serializuje do zprávy, která je odeslána klientským kanálem a přijata kanálem serveru. Pak se deserializuje a zpracuje. Všechny vrácené hodnoty jsou přenášeny kanálem serveru a přijaty klientským kanálem.
Objekt HttpChannel má přidružené vlastnosti konfigurace, které lze nastavit za běhu buď v konfiguračním souboru (vyvoláním statické RemotingConfiguration.Configure metody), nebo programově (předáním IDictionary kolekce konstruktoru HttpChannel ).
Konstruktory
| Name | Description |
|---|---|
| HttpChannel() |
Inicializuje novou instanci HttpChannel třídy. |
| HttpChannel(IDictionary, IClientChannelSinkProvider, IServerChannelSinkProvider) |
Inicializuje novou instanci HttpChannel třídy se zadanými vlastnostmi konfigurace a jímky. |
| HttpChannel(Int32) |
Inicializuje novou instanci HttpChannel třídy s kanálem serveru, který naslouchá na zadaném portu. |
Pole
| Name | Description |
|---|---|
| SinksWithProperties |
Označuje horní kanál jímku v zásobníku jímky kanálu. (Zděděno od BaseChannelWithProperties) |
Vlastnosti
| Name | Description |
|---|---|
| ChannelData |
Získá data specifická pro kanály. |
| ChannelName |
Získá název aktuálního kanálu. |
| ChannelPriority |
Získá prioritu aktuálního kanálu. |
| ChannelScheme |
Získá typ naslouchacího procesu, který se připojí (například "http"). |
| ChannelSinkChain |
Získá řetězec jímky kanálu, který používá aktuální kanál. |
| Count |
Získá počet vlastností přidružených k objektu kanálu. (Zděděno od BaseChannelObjectWithProperties) |
| IsFixedSize |
Získá hodnotu, která určuje, zda počet vlastností, které lze zadat do objektu kanálu je pevné. (Zděděno od BaseChannelObjectWithProperties) |
| IsReadOnly |
Získá hodnotu, která určuje, zda kolekce vlastností v objektu kanálu je jen pro čtení. (Zděděno od BaseChannelObjectWithProperties) |
| IsSecured |
Získá nebo nastaví logickou hodnotu, která označuje, zda je aktuální kanál zabezpečený. |
| IsSynchronized |
Získá hodnotu, která určuje, zda slovník vlastností objektu kanálu je synchronizován. (Zděděno od BaseChannelObjectWithProperties) |
| Item[Object] |
Vrátí zadanou vlastnost kanálu. |
| Keys |
ICollection Získá klíče, ke kterým jsou vlastnosti kanálu přidruženy. |
| Properties |
IDictionary Získá vlastnosti kanálu přidružené k aktuálnímu kanálu. |
| SyncRoot |
Získá objekt, který se používá k synchronizaci přístupu k objektu BaseChannelObjectWithProperties. (Zděděno od BaseChannelObjectWithProperties) |
| Values |
ICollection Získá hodnoty vlastností přidružených k objektu kanálu. (Zděděno od BaseChannelObjectWithProperties) |
| WantsToListen |
Získá logickou hodnotu, která určuje, zda aktuální instance chce být připojena k vnější službě naslouchacího procesu. |
Metody
| Name | Description |
|---|---|
| Add(Object, Object) |
Vyhodí .NotSupportedException (Zděděno od BaseChannelObjectWithProperties) |
| AddHookChannelUri(String) |
Přidá identifikátor URI, na kterém má hák kanálu naslouchat. |
| Clear() |
Vyhodí .NotSupportedException (Zděděno od BaseChannelObjectWithProperties) |
| Contains(Object) |
Vrátí hodnotu, která určuje, zda objekt kanálu obsahuje vlastnost, která je přidružena k zadanému klíči. (Zděděno od BaseChannelObjectWithProperties) |
| CopyTo(Array, Int32) |
Vyhodí .NotSupportedException (Zděděno od BaseChannelObjectWithProperties) |
| CreateMessageSink(String, Object, String) |
Vrátí jímku zpráv kanálu, která doručuje zprávy do zadané adresy URL nebo datového objektu kanálu. |
| Equals(Object) |
Určí, zda se zadaný objekt rovná aktuálnímu objektu. (Zděděno od Object) |
| GetEnumerator() |
IDictionaryEnumerator Vrátí výčet všech vlastností přidružených k objektu kanálu. (Zděděno od BaseChannelObjectWithProperties) |
| GetHashCode() |
Slouží jako výchozí funkce hash. (Zděděno od Object) |
| GetType() |
Získá Type aktuální instance. (Zděděno od Object) |
| GetUrlsForUri(String) |
Vrátí pole všech adres URL objektu se zadaným identifikátorem URI hostovaným na aktuálním HttpChannel. |
| MemberwiseClone() |
Vytvoří mělkou kopii aktuálního Object. (Zděděno od Object) |
| Parse(String, String) |
Extrahuje identifikátor URI kanálu a vzdálený dobře známý identifikátor URI objektu ze zadané adresy URL. |
| Remove(Object) |
Vyhodí .NotSupportedException (Zděděno od BaseChannelObjectWithProperties) |
| StartListening(Object) |
Dá aktuálnímu kanálu pokyn, aby začal naslouchat žádostem. |
| StopListening(Object) |
Dává aktuálnímu kanálu pokyn, aby přestal naslouchat žádostem. |
| ToString() |
Vrátí řetězec, který představuje aktuální objekt. (Zděděno od Object) |
Explicitní implementace rozhraní
| Name | Description |
|---|---|
| IEnumerable.GetEnumerator() |
IEnumerator Vrátí výčet všech vlastností přidružených k objektu kanálu. (Zděděno od BaseChannelObjectWithProperties) |
Metody rozšíření
| Name | Description |
|---|---|
| AsParallel(IEnumerable) |
Umožňuje paralelizaci dotazu. |
| AsQueryable(IEnumerable) |
Převede IEnumerable na IQueryable. |
| Cast<TResult>(IEnumerable) |
Přetypuje prvky IEnumerable na zadaný typ. |
| OfType<TResult>(IEnumerable) |
Filtruje prvky IEnumerable na základě zadaného typu. |