ActivatedClientTypeEntry Clase

Definición

Almacena valores de un tipo de objeto registrado en el cliente como un tipo que puede activarse en el servidor.

public ref class ActivatedClientTypeEntry : System::Runtime::Remoting::TypeEntry
public class ActivatedClientTypeEntry : System.Runtime.Remoting.TypeEntry
[System.Runtime.InteropServices.ComVisible(true)]
public class ActivatedClientTypeEntry : System.Runtime.Remoting.TypeEntry
type ActivatedClientTypeEntry = class
    inherit TypeEntry
[<System.Runtime.InteropServices.ComVisible(true)>]
type ActivatedClientTypeEntry = class
    inherit TypeEntry
Public Class ActivatedClientTypeEntry
Inherits TypeEntry
Herencia
ActivatedClientTypeEntry
Atributos

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar un ActivatedClientTypeEntry para registrar un objeto remoto activado por el cliente. El ejemplo contiene tres partes, un cliente, un servidor y un objeto remoto que usa el cliente y el servidor.

En el ejemplo de código siguiente se muestra un cliente:

#using <System.Runtime.Remoting.dll>
#using <ActivatedClientTypeEntry_Share.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
static void main()
{
   // Register TCP Channel.
   ChannelServices::RegisterChannel( gcnew TcpChannel );
   
   // Create activated client type entry.
   ActivatedClientTypeEntry^ activatedClientTypeEntry = gcnew ActivatedClientTypeEntry( HelloServer::typeid, "tcp://localhost:8082" );
   
   // Register type on client to activate it on the server.
   RemotingConfiguration::RegisterActivatedClientType( activatedClientTypeEntry );
   
   // Activate a client activated object type.
   HelloServer^ helloServer = gcnew HelloServer( "ParameterString" );
   
   // Print the object type.
   Console::WriteLine( "Object type of client activated object: {0}", activatedClientTypeEntry->ObjectType->ToString() );
   
   // Print the application URL.
   Console::WriteLine( "Application url where the type is activated: {0}", activatedClientTypeEntry->ApplicationUrl->ToString() );
   
   // Print the string representation of the type entry.
   Console::WriteLine( "Type and assembly name and application URL of the remote object: {0}", activatedClientTypeEntry->ToString() );
   
   // Print a blank line.
   Console::WriteLine();
   
   // Check that server was located.
   if (  !helloServer )
   {
      Console::WriteLine( "Could not locate server" );
   }
   else
   {
      Console::WriteLine( "Calling remote object" );
      Console::WriteLine( helloServer->HelloMethod( "Bill" ) );
   }
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class MyClient
{
    public static void Main()
    {
        // Register TCP Channel.
        ChannelServices.RegisterChannel(new TcpChannel());

        // Create activated client type entry.
        ActivatedClientTypeEntry myActivatedClientTypeEntry =
            new ActivatedClientTypeEntry(typeof(HelloServer),
            "tcp://localhost:8082");

        // Register type on client to activate it on the server.
        RemotingConfiguration.RegisterActivatedClientType(
            myActivatedClientTypeEntry);

        // Activate a client activated object type.
        HelloServer myHelloServer = new HelloServer("ParameterString");

        // Print the object type.
        Console.WriteLine(
            "Object type of client activated object: " +
            myActivatedClientTypeEntry.ObjectType.ToString());

        // Print the application URL.
        Console.WriteLine(
            "Application url where the type is activated: " +
            myActivatedClientTypeEntry.ApplicationUrl);

        // Print the string representation of the type entry.
        Console.WriteLine(
            "Type name, assembly name and application URL " +
            "of the remote object: " +
            myActivatedClientTypeEntry.ToString());

        // Print a blank line.
        Console.WriteLine();

        // Check that server was located.
        if (myHelloServer == null)
        {
            Console.WriteLine("Could not locate server");
        }
        else
        {
            Console.WriteLine("Calling remote object");
            Console.WriteLine(myHelloServer.HelloMethod("Bill"));
        }
    }
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp

Public Class MyClient
    
    Public Shared Sub Main()
        ' Register TCP Channel.
        ChannelServices.RegisterChannel(New TcpChannel())

        ' Create activated client type entry.
        Dim myActivatedClientTypeEntry As _
            New ActivatedClientTypeEntry(GetType(HelloServer), _
            "tcp://localhost:8082")

        ' Register type on client to activate it on the server.
        RemotingConfiguration.RegisterActivatedClientType( _
            myActivatedClientTypeEntry)

        ' Activate a client activated object type.
        Dim myHelloServer As New HelloServer("ParameterString")

        ' Print the object type.
        Console.WriteLine("Object type of client activated object: " + _
            myActivatedClientTypeEntry.ObjectType.ToString())

        ' Print the application URL.
        Console.WriteLine("Application url where the type is activated: " + _
            myActivatedClientTypeEntry.ApplicationUrl)

        ' Print the string representation of the type entry.
        Console.WriteLine( _
            "Type name, assembly name and application URL " + _
            "of the remote object: " + _
            myActivatedClientTypeEntry.ToString())

        ' Print a blank line.
        Console.WriteLine()

        ' Check that server was located.
        If myHelloServer Is Nothing Then
            Console.WriteLine("Could not locate server")
        Else
            Console.WriteLine("Calling remote object")
            Console.WriteLine(myHelloServer.HelloMethod("Bill"))
        End If
    End Sub
End Class

En el ejemplo de código siguiente se muestra un servidor para este cliente:

#using <ActivatedClientTypeEntry_Share.dll>
#using <System.Runtime.Remoting.dll>

using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
void main()
{
   ChannelServices::RegisterChannel( gcnew TcpChannel( 8082 ) );
   RemotingConfiguration::RegisterActivatedServiceType( HelloServer::typeid );
   Console::WriteLine( "Press enter to stop this process" );
   Console::ReadLine();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

public class MyServer
{
    public static void Main()
    {
        ChannelServices.RegisterChannel(new TcpChannel(8082));
        RemotingConfiguration.RegisterActivatedServiceType(typeof(HelloServer));
        Console.WriteLine("Press enter to stop this process");
        Console.ReadLine();
   }
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp

Public Class MyServer
    
    Public Shared Sub Main()
        ChannelServices.RegisterChannel(New TcpChannel(8082))
        RemotingConfiguration.RegisterActivatedServiceType(GetType(HelloServer))
        Console.WriteLine("Press enter to stop this process")
        Console.ReadLine()
    End Sub

End Class

En el ejemplo de código siguiente se proporciona el objeto remoto usado por el cliente y el servidor:

using namespace System;
public ref class HelloServer: public MarshalByRefObject
{
public:
   HelloServer( String^ myString )
   {
      Console::WriteLine( "HelloServer activated" );
      Console::WriteLine( "Paramater passed to the constructor is {0}", myString );
   }

   String^ HelloMethod( String^ myName )
   {
      Console::WriteLine( "HelloMethod : {0}", myName );
      return String::Format( "Hi there {0}", myName );
   }

};
using System;
public class HelloServer : MarshalByRefObject
{
    public HelloServer(String myString)
    {
        Console.WriteLine("HelloServer activated");
        Console.WriteLine("Parameter passed to the constructor is "+myString);
    }
    public String HelloMethod(String myName)
    {
        Console.WriteLine("HelloMethod : {0}",myName);
        return "Hi there " + myName;
    }
}
Public Class HelloServer
    Inherits MarshalByRefObject
    
    Public Sub New(myString As String)
        Console.WriteLine("HelloServer activated")
        Console.WriteLine("Parameter passed to the constructor is " + myString)
    End Sub
    
    Public Function HelloMethod(myName As String) As String
        Console.WriteLine("HelloMethod : {0}", myName)
        Return "Hi there " + myName
    End Function 'HelloMethod
End Class

Comentarios

Para crear una instancia de un objeto activado por el cliente en el cliente, debe conocer su Type y debe registrarse en el cliente mediante el RegisterActivatedClientType método . Para obtener un proxy para una nueva instancia del objeto activado por el cliente, el cliente debe registrar primero un canal con ChannelServices y, a continuación, activar el objeto llamando a new.

Para activar un tipo de objeto activado por el cliente con la new palabra clave , primero debe registrar el tipo de objeto en el cliente mediante el RegisterActivatedClientType método . Al llamar a RegisterActivatedClientType , proporciona a la infraestructura de comunicación remota la ubicación de la aplicación remota donde new intenta crearla. Por otro lado, si usa el Activator.CreateInstance método para crear una nueva instancia del objeto activado por el cliente, debe proporcionar la dirección URL de la aplicación remota como parámetro, por lo que no es necesario registrar previamente en el extremo del cliente. Para proporcionar el Activator.CreateInstance método con la dirección URL del servidor en el que desea crear el objeto, debe encapsular la dirección URL en una instancia de la UrlAttribute clase .

Para obtener una descripción detallada de los objetos activados por el cliente y la activación de objetos remotos, consulte Activación de objetos remotos.

Constructores

ActivatedClientTypeEntry(String, String, String)

Inicializa una nueva instancia de la clase ActivatedClientTypeEntry con el nombre de tipo, el nombre de ensamblado y la dirección URL de la aplicación especificados.

ActivatedClientTypeEntry(Type, String)

Inicializa una nueva instancia de la clase ActivatedClientTypeEntry con el tipo (Type) y la dirección URL de la aplicación especificados.

Propiedades

ApplicationUrl

Obtiene la dirección URL de la aplicación en la que se va a activar el tipo.

AssemblyName

Obtiene el nombre del ensamblado del tipo de objeto configurado como tipo remoto activado.

(Heredado de TypeEntry)
ContextAttributes

Obtiene o establece los atributos de contexto para el tipo activado en el cliente.

ObjectType

Obtiene el Type del tipo activado en el cliente.

TypeName

Obtiene el nombre de tipo completo del tipo de objeto configurado como tipo remoto activado.

(Heredado de TypeEntry)

Métodos

Equals(Object)

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

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve el nombre de tipo, el nombre de ensamblado y la dirección URL de la aplicación del tipo activado en el cliente en forma de String.

Se aplica a

Consulte también