HttpServerChannel 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 serverový kanál pro vzdálená volání, která k přenosu zpráv používá protokol HTTP.
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
- Dědičnost
- Implementuje
Příklady
Následující příklad kódu ukazuje, jak použít HttpServerChannel objekt 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;
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.");
}
}
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^ 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());
}
}
Následující příklad kódu ukazuje vzdálený objekt používaný serverem a klientem.
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);
}
}
Poznámky
Kanály přenášejí zprávy přes hranice vzdálené komunikace (například mezi počítači v doménách aplikací). Třída HttpServerChannel 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.
Chcete-li provést další zpracování zpráv na straně serveru, můžete určit implementaci IServerChannelSinkProvider , prostřednictvím které jsou předány všechny zprávy zpracovávané serverem HttpServerChannel .
Přijímá HttpServerChannel zprávy serializované v binárním nebo SOAP formátu.
Objekt HttpServerChannel 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 HttpServerChannel ). Seznam těchto vlastností konfigurace naleznete v dokumentaci pro HttpServerChannel.
Konstruktory
| Name | Description |
|---|---|
| HttpServerChannel() |
Inicializuje novou instanci HttpServerChannel třídy. |
| HttpServerChannel(IDictionary, IServerChannelSinkProvider) |
Inicializuje novou instanci HttpServerChannel třídy se zadanými vlastnostmi kanálu a jímkou. |
| HttpServerChannel(Int32) |
Inicializuje novou instanci HttpServerChannel třídy, která naslouchá na zadaném portu. |
| HttpServerChannel(String, Int32, IServerChannelSinkProvider) |
Inicializuje novou instanci HttpServerChannel třídy na zadaném portu s daným názvem, který naslouchá na zadaném portu a používá zadanou jímku. |
| HttpServerChannel(String, Int32) |
Inicializuje novou instanci HttpServerChannel třídy s daným názvem a 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) |
| 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žené. |
| Properties |
IDictionary Získá vlastnosti kanálu přidružené k aktuálnímu objektu kanálu. (Zděděno od BaseChannelWithProperties) |
| 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á označuje, zda IChannelReceiverHook se má připojit 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 musí 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) |
| Equals(Object) |
Určí, zda se zadaný objekt rovná aktuálnímu objektu. (Zděděno od Object) |
| GetChannelUri() |
Vrátí identifikátor URI aktuálního kanálu. |
| 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. |