TcpServerChannel Classe

Definição

Implementa um canal de servidor para chamadas remotas, que usa o protocolo TCP para transmitir mensagens.

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
Herança
TcpServerChannel
Implementações

Exemplos

O exemplo de código a seguir mostra o uso de um tipo remoto.

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

O exemplo de código a seguir mostra o uso da TcpServerChannel classe para expor um tipo remoto.

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

Comentários

Importante

Chamar métodos desta classe quando você tiver dados não confiáveis é um risco à segurança. Chame os métodos dessa classe somente quando você tiver dados confiáveis. Para obter mais informações, consulte Validar todas as entradas.

Os canais transportam mensagens entre limites de comunicação remota (por exemplo, computadores ou domínios de aplicativo). A TcpServerChannel classe transporta mensagens usando o protocolo TCP.

Os canais são usados pela infraestrutura de comunicação remota .NET Framework para transportar chamadas remotas. Quando um cliente faz uma chamada para um objeto remoto, a chamada é serializada em uma mensagem enviada por um canal cliente e recebida por um canal de servidor. Em seguida, ele é desserializado e processado. Todos os valores retornados são transmitidos pelo canal do servidor e recebidos pelo canal cliente.

Para executar processamento adicional de mensagens no lado do servidor, você pode especificar uma implementação da interface por meio da IServerChannelSinkProvider qual todas as mensagens processadas pela TcpServerChannel instância são passadas.

A TcpServerChannel instância aceita mensagens serializadas no formato binário ou SOAP.

Um TcpServerChannel objeto tem propriedades de configuração associadas que podem ser definidas em tempo de execução em um arquivo de configuração (invocando o método estático RemotingConfiguration.Configure ) ou programaticamente (passando uma IDictionary coleção para o TcpServerChannel construtor). Para obter uma lista dessas propriedades de configuração, consulte Propriedades de configuração de canal e formatador.

Construtores

TcpServerChannel(IDictionary, IServerChannelSinkProvider)

Inicializa uma nova instância da classe TcpServerChannel com as propriedades de canal e os coletores especificados.

TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection)

Inicializa uma nova instância da classe TcpServerChannel com propriedades de canal, coletor e provedor de autorização especificados.

TcpServerChannel(Int32)

Inicializa uma nova instância da classe TcpServerChannel que escuta na porta especificada.

TcpServerChannel(String, Int32)

Inicializa uma nova instância da classe TcpServerChannel com o nome fornecido e que escuta na porta especificada.

TcpServerChannel(String, Int32, IServerChannelSinkProvider)

Inicializa uma nova instância da classe TcpServerChannel com o nome fornecido, que escuta na porta especificada e usa o coletor especificado.

Propriedades

ChannelData

Obtém dados específicos do canal.

ChannelName

Obtém o nome do canal atual.

ChannelPriority

Obtém a prioridade do canal atual.

IsSecured

Obtém ou define um valor booliano que indica se o canal atual é seguro.

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetChannelUri()

Retorna o URI do canal atual.

GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
GetUrlsForUri(String)

Retorna uma matriz de todas as URLs para um objeto com o URI especificado, hospedado na instância TcpChannel atual.

MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
Parse(String, String)

Extrai o URI do canal e o URI do objeto bem conhecido remoto da URL especificada.

StartListening(Object)

Instrui o canal atual a iniciar a escuta em um canal depois que o método StopListening(Object) é chamado para interromper a escuta no canal.

StopListening(Object)

Instrui o canal atual a parar de escutar solicitações.

ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a