TcpClientChannel Classe

Definição

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

public ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSender
public ref class TcpClientChannel : System::Runtime::Remoting::Channels::IChannelSender, System::Runtime::Remoting::Channels::ISecurableChannel
public class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSender
public class TcpClientChannel : System.Runtime.Remoting.Channels.IChannelSender, System.Runtime.Remoting.Channels.ISecurableChannel
type TcpClientChannel = class
    interface IChannelSender
    interface IChannel
type TcpClientChannel = class
    interface IChannelSender
    interface IChannel
    interface ISecurableChannel
Public Class TcpClientChannel
Implements IChannelSender
Public Class TcpClientChannel
Implements IChannelSender, ISecurableChannel
Herança
TcpClientChannel
Implementações

Exemplos

O exemplo de código a seguir mostra o uso da TcpClientChannel classe para chamar 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 client channel.
   TcpClientChannel^ clientChannel = gcnew TcpClientChannel;
   ChannelServices::RegisterChannel( clientChannel );
   
   // Show the name and priority of the channel.
   Console::WriteLine( "Channel Name: {0}", clientChannel->ChannelName );
   Console::WriteLine( "Channel Priority: {0}", clientChannel->ChannelPriority );
   
   // Obtain a proxy for a remote object.
   RemotingConfiguration::RegisterWellKnownClientType( Remotable::typeid, "tcp://localhost:9090/Remotable.rem" );
   
   // Call a method on the object.
   Remotable ^ remoteObject = gcnew Remotable;
   Console::WriteLine( remoteObject->GetCount() );
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class Client
{
    public static void Main()
    {

        // Set up a client channel.
        TcpClientChannel clientChannel = new TcpClientChannel();
        ChannelServices.RegisterChannel(clientChannel);

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

        // Obtain a proxy for a remote object.
        RemotingConfiguration.RegisterWellKnownClientType(
            typeof(Remotable), "tcp://localhost:9090/Remotable.rem"
        );

        // Call a method on the object.
        Remotable remoteObject = new Remotable();
        Console.WriteLine( remoteObject.GetCount() );
    }
}

O tipo remoto chamado no exemplo acima é definido pelo código a seguir.

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

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 TcpClientChannel 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 cliente, você pode especificar uma implementação da interface por meio da IClientChannelSinkProvider qual todas as mensagens processadas pelo TcpClientChannel são passadas.

Por padrão, a TcpClientChannel classe usa um formatador binário para serializar todas as mensagens.

Um TcpClientChannel 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 TcpClientChannel construtor). Para obter uma lista dessas propriedades de configuração, consulte a documentação de TcpClientChannel.

Construtores

TcpClientChannel()

Inicializa uma nova instância da classe TcpClientChannel.

TcpClientChannel(IDictionary, IClientChannelSinkProvider)

Inicializa uma nova instância da classe TcpClientChannel com as propriedades de configuração e o coletor especificados.

TcpClientChannel(String, IClientChannelSinkProvider)

Inicializa uma nova instância da classe TcpClientChannel com o nome e o coletor especificados.

Propriedades

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

CreateMessageSink(String, Object, String)

Retorna um coletor de mensagem de canal que entrega mensagens ao objeto de dados de URL ou de canal especificado.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
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)
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.

ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a