TcpServerChannel 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.
Implementa um canal de servidor para chamadas remotas que utiliza 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 seguinte exemplo de código 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 seguinte mostra a utilização 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();
}
}
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 TcpServerChannel 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 das mensagens do lado do servidor, pode especificar uma implementação da IServerChannelSinkProvider interface através da qual todas as mensagens processadas pela TcpServerChannel instância são passadas.
A TcpServerChannel instância aceita mensagens serializadas em formato binário ou SOAP.
Um TcpServerChannel 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 TcpServerChannel construtor). Para uma lista destas propriedades de configuração, veja Propriedades de Configuração de Canal e Formator.
Construtores
| Name | Description |
|---|---|
| TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection) |
Inicializa uma nova instância da TcpServerChannel classe com as propriedades do canal especificadas, o sumidouro e o fornecedor de autorização. |
| TcpServerChannel(IDictionary, IServerChannelSinkProvider) |
Inicializa uma nova instância da TcpServerChannel classe com as propriedades do canal e o sumidouro especificados. |
| TcpServerChannel(Int32) |
Inicializa uma nova instância da TcpServerChannel classe que escuta na porta especificada. |
| TcpServerChannel(String, Int32, IServerChannelSinkProvider) |
Inicializa uma nova instância da TcpServerChannel classe com o nome próprio, que ouve na porta especificada e utiliza o sumidouro especificado. |
| TcpServerChannel(String, Int32) |
Inicializa uma nova instância da TcpServerChannel classe com o nome próprio e que escuta na porta especificada. |
Propriedades
| Name | Description |
|---|---|
| ChannelData |
Obtém dados específicos do canal. |
| 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 |
|---|---|
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| GetChannelUri() |
Devolve o URI do canal atual. |
| GetHashCode() |
Serve como função de hash predefinida. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| GetUrlsForUri(String) |
Devolve um array de todas as URLs de um objeto com o URI especificado, alojado na instância atual TcpChannel . |
| 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. |
| StartListening(Object) |
Instrui o canal atual a começar a ouvir num canal, depois de o StopListening(Object) método ter sido chamado, para parar de ouvir no canal. |
| StopListening(Object) |
Instrui o canal atual a parar de ouvir pedidos. |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |