Share via


HttpChannel Třída

Definice

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í serveru vzdálené komunikace 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. Metody z této třídy volejte pouze s důvěryhodnými daty. Další informace najdete v tématu Ověření všech vstupů.

Kanály přenáší zprávy přes hranice vzdálené komunikace (například mezi počítači nebo doménami aplikací). Třída HttpChannel přenáší zprávy pomocí protokolu HTTP.

Kanály se používají v infrastruktuře vzdálené komunikace rozhraní .NET Framework k přenosu vzdálených volání. Když klient provede volání vzdáleného objektu, volání je serializováno do zprávy, která je odeslána klientským kanálem a přijata kanálem serveru. Poté 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 ). Seznam těchto vlastností konfigurace najdete v tématu Vlastnosti konfigurace kanálu a formátovače.

Konstruktory

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 se serverovým kanálem, který naslouchá na zadaném portu.

Pole

SinksWithProperties

Označuje jímku horního kanálu v zásobníku jímky kanálu.

(Zděděno od BaseChannelWithProperties)

Vlastnosti

ChannelData

Získá data specifická pro kanál.

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, ke které se má připojit (například http).

ChannelSinkChain

Získá řetězec jímky kanálu, který aktuální kanál používá.

Count

Získá počet vlastností přidružených k objektu kanálu.

(Zděděno od BaseChannelObjectWithProperties)
IsFixedSize

Získá hodnotu, která označuje, zda počet vlastností, které lze zadat do objektu kanálu je pevná.

(Zděděno od BaseChannelObjectWithProperties)
IsReadOnly

Získá hodnotu, která označ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á označuje, zda je slovník vlastností objektu kanálu 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 přidruženy vlastnosti kanálu.

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 .BaseChannelObjectWithProperties

(Zděděno od BaseChannelObjectWithProperties)
Values

ICollection Získá hodnotu vlastností přidružených k objektu kanálu.

(Zděděno od BaseChannelObjectWithProperties)
WantsToListen

Získá boolean hodnotu, která označuje, zda aktuální instance chce být připojena k vnější službě naslouchacího procesu.

Metody

Add(Object, Object)

Vyvolá .NotSupportedException

(Zděděno od BaseChannelObjectWithProperties)
AddHookChannelUri(String)

Přidá identifikátor URI, na kterém by měl kanál naslouchat.

Clear()

Vyvolá .NotSupportedException

(Zděděno od BaseChannelObjectWithProperties)
Contains(Object)

Vrátí hodnotu, která označ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)

Vyvolá .NotSupportedException

(Zděděno od BaseChannelObjectWithProperties)
CreateMessageSink(String, Object, String)

Vrátí jímku zpráv kanálu, která doručuje zprávy na zadanou adresu URL nebo datový objekt kanálu.

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetEnumerator()

Vrátí hodnotu IDictionaryEnumerator , která vytvoří výčet všech vlastností přidružených k objektu kanálu.

(Zděděno od BaseChannelObjectWithProperties)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Type Získá z 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 v aktuálním HttpChannelobjektu .

MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
Parse(String, String)

Extrahuje identifikátor URI kanálu a identifikátor URI vzdáleného známého objektu ze zadané adresy URL.

Remove(Object)

Vyvolá .NotSupportedException

(Zděděno od BaseChannelObjectWithProperties)
StartListening(Object)

Dá aktuálnímu kanálu pokyn, aby začal naslouchat žádostem.

StopListening(Object)

Dá 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í

IEnumerable.GetEnumerator()

Vrátí hodnotu IEnumerator , která vytvoří výčet všech vlastností, které jsou přidruženy k objektu kanálu.

(Zděděno od BaseChannelObjectWithProperties)

Metody rozšíření

Cast<TResult>(IEnumerable)

Přetypuje prvky objektu na IEnumerable zadaný typ.

OfType<TResult>(IEnumerable)

Filtruje prvky objektu IEnumerable na základě zadaného typu.

AsParallel(IEnumerable)

Umožňuje paralelizaci dotazu.

AsQueryable(IEnumerable)

Převede objekt na IEnumerableIQueryable.

Platí pro

Viz také