TcpClientChannel Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Para chamadas remotas, implementa um canal cliente que utiliza 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 seguinte exemplo de código 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 seguinte código.
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);
}
}
Observações
Importante
Chamar métodos dessa classe com dados não confiáveis é um risco de segurança. Chame os métodos dessa classe somente com dados confiáveis. Para obter mais informações, consulte Validar todas as informações inseridas.
Os canais transportam mensagens através de fronteiras remotas (por exemplo, computadores ou domínios de aplicação). A TcpClientChannel classe transporta mensagens usando o protocolo TCP.
Os canais são usados pela infraestrutura remota do .NET Framework para transportar chamadas remotas. Quando um cliente faz uma chamada para um objeto remoto, a chamada é serializada numa mensagem enviada por um canal cliente e recebida por um canal servidor. Depois, é desserializado e processado. Quaisquer valores devolvidos são transmitidos pelo canal do servidor e recebidos pelo canal cliente.
Para realizar um processamento adicional de mensagens do lado do cliente, pode especificar uma implementação da IClientChannelSinkProvider interface através da qual todas as mensagens processadas pelo TcpClientChannel são passadas.
Por defeito, a TcpClientChannel classe utiliza 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, seja num ficheiro de configuração (invocando o método estático RemotingConfiguration.Configure ) ou programaticamente (passando uma IDictionary coleção ao TcpClientChannel construtor). Para uma lista destas propriedades de configuração, consulte a documentação para TcpClientChannel.
Construtores
| Name | Description |
|---|---|
| TcpClientChannel() |
Inicializa uma nova instância da TcpClientChannel classe. |
| TcpClientChannel(IDictionary, IClientChannelSinkProvider) |
Inicializa uma nova instância da TcpClientChannel classe com as propriedades de configuração e o sink especificados. |
| TcpClientChannel(String, IClientChannelSinkProvider) |
Inicializa uma nova instância da TcpClientChannel classe com o nome e o sumidouro especificados. |
Propriedades
| Name | Description |
|---|---|
| ChannelName |
Recebe o nome do canal atual. |
| ChannelPriority |
Recebe a prioridade do canal atual. |
| IsSecured |
Recebe ou define um valor booleano que indica se o canal atual é seguro. |
Métodos
| Name | Description |
|---|---|
| CreateMessageSink(String, Object, String) |
Devolve um dissipador de mensagens de canal que entrega 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 função de hash predefinida. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| Parse(String, String) |
Extrai o URI do canal e o URI remoto do objeto conhecido a partir da URL especificada. |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |