TcpServerChannel Clase

Definición

Implementa un canal de servidor para llamadas remotas que utiliza el protocolo TCP para transmitir los 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 supone 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.

Los canales transportan 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 de comunicación 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 procesa. Los valores devueltos se transmiten por el canal de 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). Para obtener una lista de estas propiedades de configuración, vea Propiedades de configuración de canal y formateador.

Constructores

TcpServerChannel(IDictionary, IServerChannelSinkProvider)

Inicializa una nueva instancia de la clase TcpServerChannel con las propiedades de canal y el receptor especificados.

TcpServerChannel(IDictionary, IServerChannelSinkProvider, IAuthorizeRemotingConnection)

Inicializa una nueva instancia de la clase TcpServerChannel con las propiedades de canal, el receptor y el proveedor de autorización especificados.

TcpServerChannel(Int32)

Inicializa una nueva instancia de la clase TcpServerChannel que escucha en el puerto especificado.

TcpServerChannel(String, Int32)

Inicializa una nueva instancia de la clase TcpServerChannel con el nombre indicado y que realiza la escucha en el puerto especificado.

TcpServerChannel(String, Int32, IServerChannelSinkProvider)

Inicializa una nueva instancia de la clase TcpServerChannel con el nombre de pila indicado, que realiza la escucha en el puerto especificado y utiliza el receptor especificado.

Propiedades

ChannelData

Obtiene los 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

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetChannelUri()

Devuelve la dirección URI del canal actual.

GetHashCode()

Sirve como la 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 la dirección URI especificada, hospedadas en la instancia de TcpChannel actual.

MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
Parse(String, String)

Extrae el identificador URI del canal y el identificador 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 método StopListening(Object) para detener la escucha en el canal.

StopListening(Object)

Indica al canal actual que detenga la escucha de solicitudes.

ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a