TcpServerChannel Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Implementa un canal de servidor para llamadas remotas que usa el protocolo TCP para transmitir mensajes.
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
- Herencia
-
TcpServerChannel
- Implementaciones
Ejemplos
En el ejemplo de código siguiente se muestra el uso de un tipo remotable.
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);
}
}
En el ejemplo de código siguiente se muestra el uso de la TcpServerChannel clase para exponer un tipo remotable.
#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();
}
}
Comentarios
Importante
Llamar a métodos de esta clase con datos que no son de confianza es un riesgo de seguridad. Llame a los métodos de esta clase solo con datos de confianza. Para obtener más información, vea Validar todas las entradas.
Canales transporta mensajes a través de límites de comunicación remota (por ejemplo, equipos o dominios de aplicación). La TcpServerChannel clase transporta mensajes mediante el protocolo TCP.
La infraestructura remota de .NET Framework usa canales para transportar llamadas remotas. Cuando un cliente realiza una llamada a un objeto remoto, la llamada se serializa en un mensaje enviado por un canal de cliente y recibido por un canal de servidor. A continuación, se deserializa y se procesa. Los valores devueltos se transmiten por el canal del servidor y los recibe el canal de cliente.
Para realizar un procesamiento adicional de mensajes en el lado servidor, puede especificar una implementación de la interfaz a través de la IServerChannelSinkProvider cual se pasan todos los mensajes procesados por la TcpServerChannel instancia.
La TcpServerChannel instancia acepta mensajes serializados en formato binario o SOAP.
Un TcpServerChannel objeto tiene propiedades de configuración asociadas que se pueden establecer en tiempo de ejecución en un archivo de configuración (invocando el método estático RemotingConfiguration.Configure ) o mediante programación (pasando una IDictionary colección al TcpServerChannel constructor).
Constructores
| Nombre | Description |
|---|---|
| TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection) |
Inicializa una nueva instancia de la TcpServerChannel clase con las propiedades del canal, el receptor y el proveedor de autorización especificados. |
| TcpServerChannel(IDictionary, IServerChannelSinkProvider) |
Inicializa una nueva instancia de la TcpServerChannel clase con las propiedades del canal y el receptor especificados. |
| TcpServerChannel(Int32) |
Inicializa una nueva instancia de la TcpServerChannel clase que escucha en el puerto especificado. |
| TcpServerChannel(String, Int32, IServerChannelSinkProvider) |
Inicializa una nueva instancia de la TcpServerChannel clase con el nombre especificado, que escucha en el puerto especificado y usa el receptor especificado. |
| TcpServerChannel(String, Int32) |
Inicializa una nueva instancia de la TcpServerChannel clase con el nombre especificado y que escucha en el puerto especificado. |
Propiedades
| Nombre | Description |
|---|---|
| ChannelData |
Obtiene datos específicos del canal. |
| ChannelName |
Obtiene el nombre del canal actual. |
| ChannelPriority |
Obtiene la prioridad del canal actual. |
| IsSecured |
Obtiene o establece un valor booleano que indica si el canal actual es seguro. |
Métodos
| Nombre | Description |
|---|---|
| Equals(Object) |
Determina si el objeto especificado es igual que el objeto actual. (Heredado de Object) |
| GetChannelUri() |
Devuelve el URI del canal actual. |
| GetHashCode() |
Sirve como función hash predeterminada. (Heredado de Object) |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| GetUrlsForUri(String) |
Devuelve una matriz de todas las direcciones URL de un objeto con el URI especificado, hospedado en la instancia actual TcpChannel . |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| Parse(String, String) |
Extrae el URI del canal y el URI del objeto conocido remoto de la dirección URL especificada. |
| StartListening(Object) |
Indica al canal actual que empiece a escuchar en un canal después de llamar al StopListening(Object) método para dejar de escuchar en el canal. |
| StopListening(Object) |
Indica al canal actual que deje de escuchar solicitudes. |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |