ActivatedClientTypeEntry 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.
Detém valores para um tipo de objeto registado na extremidade do cliente como um tipo que pode ser ativado no 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
- Herança
- Atributos
Exemplos
O seguinte exemplo de código mostra como usar um ActivatedClientTypeEntry para registar um objeto remoto ativado pelo cliente. O exemplo contém três partes: um cliente, um servidor e um objeto remoto usado pelo cliente e pelo servidor.
O seguinte exemplo de código mostra um 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
O seguinte exemplo de código mostra um 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
O seguinte exemplo de código fornece o objeto remoto usado pelo cliente e pelo 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
Observações
Para criar uma instância de um objeto ativado pelo cliente no cliente, deve conhecê-lo Type e deve ser registado no cliente usando o RegisterActivatedClientType método. Para obter um proxy para uma nova instância do objeto ativado pelo cliente, o cliente deve primeiro registar um canal com ChannelServices e depois ativar o objeto chamando new.
Para ativar um tipo de objeto ativado pelo cliente com a new palavra-chave, deve primeiro registar o tipo de objeto no cliente usando o RegisterActivatedClientType método. Ao ligar RegisterActivatedClientType , está a fornecer à infraestrutura remota a localização da aplicação remota onde new tenta criá-la. Se, por outro lado, usar o Activator.CreateInstance método para criar uma nova instância do objeto ativado pelo cliente, deve fornecer a URL da aplicação remota como parâmetro, pelo que não é necessário registo prévio do lado do cliente. Para fornecer ao Activator.CreateInstance método a URL do servidor onde pretende criar o objeto, deve encapsular o URL numa instância da UrlAttribute classe.
Para uma descrição detalhada dos objetos ativados pelo cliente e da ativação remota de objetos, veja Ativação de Objetos Remotos.
Construtores
| Name | Description |
|---|---|
| ActivatedClientTypeEntry(String, String, String) |
Inicializa uma nova instância da ActivatedClientTypeEntry classe com o nome do tipo, nome de montagem e URL da aplicação. |
| ActivatedClientTypeEntry(Type, String) |
Inicializa uma nova instância da ActivatedClientTypeEntry classe com a URL da aplicação e indicada Type . |
Propriedades
| Name | Description |
|---|---|
| ApplicationUrl |
Obtém o URL da aplicação para ativar o tipo de entrada. |
| AssemblyName |
Obtém o nome de montagem do tipo de objeto configurado para ser um tipo ativado remotamente. (Herdado de TypeEntry) |
| ContextAttributes |
Obtém ou define os atributos de contexto para o tipo ativado pelo cliente. |
| ObjectType |
Fica com o Type tipo ativado pelo cliente. |
| TypeName |
Obtém o nome completo do tipo de objeto configurado para ser um tipo ativado remotamente. (Herdado de TypeEntry) |
Métodos
| Name | Description |
|---|---|
| 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) |
| ToString() |
Devolve o nome do tipo, o nome da assembleia e a URL da aplicação do tipo ativado pelo cliente como um String. |