Udostępnij za pośrednictwem


TcpServerChannel Klasa

Definicja

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

public ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiver
public ref class TcpServerChannel : System::Runtime::Remoting::Channels::IChannelReceiver, System::Runtime::Remoting::Channels::ISecurableChannel
public class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiver
public class TcpServerChannel : System.Runtime.Remoting.Channels.IChannelReceiver, System.Runtime.Remoting.Channels.ISecurableChannel
type TcpServerChannel = class
    interface IChannelReceiver
    interface IChannel
type TcpServerChannel = class
    interface IChannelReceiver
    interface IChannel
    interface ISecurableChannel
Public Class TcpServerChannel
Implements IChannelReceiver
Public Class TcpServerChannel
Implements IChannelReceiver, ISecurableChannel
Dziedziczenie
TcpServerChannel
Implementuje

Przykłady

Poniższy przykład kodu przedstawia użycie typu remotable.

using namespace System;
using namespace System::Runtime::Remoting;

public ref class Remotable: public MarshalByRefObject
{
private:
   int callCount;

public:
   Remotable()
      : callCount( 0 )
   {}

   int GetCount()
   {
      callCount++;
      return (callCount);
   }
};
using System;
using System.Runtime.Remoting;

public class Remotable : MarshalByRefObject
{

    private int callCount = 0;

    public int GetCount()
    {
        callCount++;
        return(callCount);
    }
}

Poniższy przykład kodu przedstawia użycie TcpServerChannel klasy w celu uwidocznienia typu remotable.

#using <System.Runtime.Remoting.dll>
#using <System.dll>
#using <Remotable.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;

int main()
{
   // Set up a server channel.
   TcpServerChannel^ serverChannel = gcnew TcpServerChannel( 9090 );
   ChannelServices::RegisterChannel( serverChannel );

   // Expose an object for remote calls.
   RemotingConfiguration::RegisterWellKnownServiceType( Remotable::typeid, "Remotable.rem", WellKnownObjectMode::Singleton );

   // Show the name and priority of the channel.
   Console::WriteLine( "Channel Name: {0}", serverChannel->ChannelName );
   Console::WriteLine( "Channel Priority: {0}", serverChannel->ChannelPriority );

   // Show the URIs associated with the channel.
   ChannelDataStore^ data = dynamic_cast<ChannelDataStore^>(serverChannel->ChannelData);
   System::Collections::IEnumerator^ myEnum = data->ChannelUris->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      String^ uri = safe_cast<String^>(myEnum->Current);
      Console::WriteLine( uri );
   }

   // Wait for method calls.
   Console::WriteLine( "Listening..." );
   Console::ReadLine();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Server
{
    public static void Main()
    {

        // Set up a server channel.
        TcpServerChannel serverChannel = new TcpServerChannel(9090);
        ChannelServices.RegisterChannel(serverChannel);

        // Expose an object for remote calls.
        RemotingConfiguration.RegisterWellKnownServiceType(
            typeof(Remotable), "Remotable.rem", WellKnownObjectMode.Singleton
        );

        // Show the name and priority of the channel.
        Console.WriteLine("Channel Name: {0}", serverChannel.ChannelName);
        Console.WriteLine("Channel Priority: {0}", serverChannel.ChannelPriority);

        // Show the URIs associated with the channel.
        ChannelDataStore data = (ChannelDataStore) serverChannel.ChannelData;
        foreach (string uri in data.ChannelUris)
        {
            Console.WriteLine(uri);
        }

        // Wait for method calls.
        Console.WriteLine("Listening...");
        Console.ReadLine();
    }
}

Uwagi

Ważne

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 Weryfikowanie wszystkich danych wejściowych.

Kanały transportują komunikaty przez granice komunikacji zdalnie (na przykład komputery lub domeny aplikacji). Klasa TcpServerChannel transportuje komunikaty przy użyciu protokołu TCP.

Kanały są używane przez infrastrukturę komunikacji zdalnej .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 odbierane 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 interfejsu, za pomocą którego przekazywane są wszystkie komunikaty przetwarzane przez TcpServerChannel wystąpienie.

Wystąpienie TcpServerChannel akceptuje komunikaty serializowane w formacie binarnym lub SOAP.

Obiekt TcpServerChannel 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 TcpServerChannel ). Aby uzyskać listę tych właściwości konfiguracji, zobacz Właściwości konfiguracji kanału i formatnika.

Konstruktory

TcpServerChannel(IDictionary, IServerChannelSinkProvider)

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

TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection)

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

TcpServerChannel(Int32)

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

TcpServerChannel(String, Int32)

Inicjuje TcpServerChannel nowe wystąpienie klasy o podanej nazwie i nasłuchuje na określonym porcie.

TcpServerChannel(String, Int32, IServerChannelSinkProvider)

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

Właściwości

ChannelData

Pobiera dane specyficzne dla kanału.

ChannelName

Pobiera nazwę bieżącego kanału.

ChannelPriority

Pobiera priorytet bieżącego kanału.

IsSecured

Pobiera lub ustawia wartość logiczną wskazującą, czy bieżący kanał jest bezpieczny.

Metody

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.

GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
GetUrlsForUri(String)

Zwraca tablicę wszystkich adresów URL obiektu z określonym identyfikatorem URI hostowanym w bieżącym TcpChannel wystąpieniu.

MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
Parse(String, String)

Wyodrębnia identyfikator URI kanału i zdalny dobrze znany identyfikator URI obiektu z określonego adresu URL.

StartListening(Object)

Nakazuje bieżącemu kanałowi rozpoczęcie nasłuchiwania w kanale po StopListening(Object) wywołaniu metody w celu zatrzymania nasłuchiwania w kanale.

StopListening(Object)

Instruuje bieżący kanał, aby przestał nasłuchiwać żądań.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy