TcpClientChannel Classe
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Para chamadas remotas, implementa um canal cliente 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 TcpClientChannel seguir mostra o uso da 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 dessa classe com dados não confiáveis é um risco à segurança. Chame os métodos dessa classe apenas com 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 do .NET Framework para transportar chamadas remotas. Quando um cliente faz uma chamada para um objeto remoto, a chamada é serializada em uma mensagem que é 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 do cliente.
Para executar o 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 cliente 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 para TcpClientChannel.
Construtores
| Nome | Description |
|---|---|
| TcpClientChannel() |
Inicializa uma nova instância da classe TcpClientChannel. |
| TcpClientChannel(IDictionary, IClientChannelSinkProvider) |
Inicializa uma nova instância da TcpClientChannel classe com as propriedades de configuração e o coletor especificados. |
| TcpClientChannel(String, IClientChannelSinkProvider) |
Inicializa uma nova instância da TcpClientChannel classe com o nome e o coletor especificados. |
Propriedades
| Nome | Description |
|---|---|
| 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
| Nome | Description |
|---|---|
| CreateMessageSink(String, Object, String) |
Retorna um coletor de mensagens de canal que fornece mensagens para a URL especificada ou objeto de dados de canal. |
| 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 Objectatual. (Herdado de Object) |
| Parse(String, String) |
Extrai o URI do canal e o URI de objeto conhecido remoto da URL especificada. |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual. (Herdado de Object) |