HttpServerChannel Klasa

Definicja

Implementuje kanał serwera dla wywołań zdalnych, które używają protokołu HTTP do przesyłania komunikatów.

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
Dziedziczenie
Implementuje

Przykłady

W poniższym przykładzie kodu pokazano, jak za pomocą HttpServerChannel obiektu skonfigurować serwer komunikacji zdalnie i jego klienta. 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;

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.");
    }
}

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^ 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());
    }
}

Poniższy przykład kodu przedstawia obiekt zdalny używany przez serwer i klienta.

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);
    }
}

Uwagi

Kanały transportują komunikaty przez granice komunikacji zdalnie (na przykład między komputerami w domenach aplikacji). Klasa HttpServerChannel 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.

Aby wykonać dodatkowe przetwarzanie komunikatów po stronie serwera, można określić implementację IServerChannelSinkProvider , za pomocą której przekazywane są wszystkie komunikaty przetwarzane przez HttpServerChannel .

Element HttpServerChannel akceptuje komunikaty serializowane w formacie binarnym lub SOAP.

Obiekt HttpServerChannel 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 HttpServerChannel ). Aby uzyskać listę tych właściwości konfiguracji, zobacz dokumentację dotyczącą HttpServerChannelprogramu .

Konstruktory

Nazwa Opis
HttpServerChannel()

Inicjuje nowe wystąpienie klasy HttpServerChannel.

HttpServerChannel(IDictionary, IServerChannelSinkProvider)

Inicjuje nowe wystąpienie HttpServerChannel klasy z określonymi właściwościami kanału i ujściem.

HttpServerChannel(Int32)

Inicjuje nowe wystąpienie HttpServerChannel klasy, która nasłuchuje na określonym porcie.

HttpServerChannel(String, Int32, IServerChannelSinkProvider)

Inicjuje nowe wystąpienie HttpServerChannel klasy na określonym porcie o podanej nazwie, która nasłuchuje na określonym porcie i używa określonego ujścia.

HttpServerChannel(String, Int32)

Inicjuje HttpServerChannel nowe wystąpienie klasy o podanej nazwie i 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)
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órych są skojarzone właściwości kanału.

Properties

Pobiera właściwości IDictionary kanału skojarzone z bieżącym obiektem kanału.

(Odziedziczone po BaseChannelWithProperties)
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ą, która wskazuje, czy IChannelReceiverHook chcesz zostać podłączony 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 musi 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)
Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetChannelUri()

Zwraca identyfikator URI bieżącego kanału.

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.

Dotyczy