ClientSponsor 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í.
Proporciona una implementación predeterminada para una clase patrocinadora de duración.
public ref class ClientSponsor : MarshalByRefObject, System::Runtime::Remoting::Lifetime::ISponsor
public class ClientSponsor : MarshalByRefObject, System.Runtime.Remoting.Lifetime.ISponsor
[System.Runtime.InteropServices.ComVisible(true)]
public class ClientSponsor : MarshalByRefObject, System.Runtime.Remoting.Lifetime.ISponsor
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public class ClientSponsor : MarshalByRefObject, System.Runtime.Remoting.Lifetime.ISponsor
type ClientSponsor = class
inherit MarshalByRefObject
interface ISponsor
[<System.Runtime.InteropServices.ComVisible(true)>]
type ClientSponsor = class
inherit MarshalByRefObject
interface ISponsor
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type ClientSponsor = class
inherit MarshalByRefObject
interface ISponsor
Public Class ClientSponsor
Inherits MarshalByRefObject
Implements ISponsor
- Herencia
- Atributos
- Implementaciones
Ejemplos
En el ejemplo siguiente se muestra la clase ClientSponsor para ampliar la vida de un objeto remoto activado por clases.
#using <system.dll>
#using <system.runtime.remoting.dll>
#using <ClientSponsor_Share.dll>
using namespace System;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Channels;
using namespace System::Runtime::Remoting::Channels::Tcp;
using namespace System::Runtime::Remoting::Lifetime;
int main()
{
// Register a channel.
TcpChannel^ myChannel = gcnew TcpChannel;
ChannelServices::RegisterChannel( myChannel );
RemotingConfiguration::RegisterActivatedClientType(
RemotingSamples::HelloService::typeid, "tcp://localhost:8085/" );
// Get the remote Object*.
RemotingSamples::HelloService ^ myService = gcnew RemotingSamples::HelloService;
// Get a sponsor for renewal of time.
ClientSponsor^ mySponsor = gcnew ClientSponsor;
// Register the service with sponsor.
mySponsor->Register( myService );
// Set renewaltime.
mySponsor->RenewalTime = TimeSpan::FromMinutes( 2 );
// Renew the lease.
ILease^ myLease = dynamic_cast<ILease^>(mySponsor->InitializeLifetimeService());
TimeSpan myTime = mySponsor->Renewal( myLease );
Console::WriteLine( "Renewed time in minutes is {0}", myTime.Minutes );
// Call the remote method.
Console::WriteLine( myService->HelloMethod( "World" ) );
// Unregister the channel.
mySponsor->Unregister( myService );
mySponsor->Close();
}
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Lifetime;
namespace RemotingSamples
{
class HelloClient
{
static void Main()
{
// Register a channel.
TcpChannel myChannel = new TcpChannel ();
ChannelServices.RegisterChannel(myChannel);
RemotingConfiguration.RegisterActivatedClientType(
typeof(HelloService),"tcp://localhost:8085/");
// Get the remote object.
HelloService myService = new HelloService();
// Get a sponsor for renewal of time.
ClientSponsor mySponsor = new ClientSponsor();
// Register the service with sponsor.
mySponsor.Register(myService);
// Set renewaltime.
mySponsor.RenewalTime = TimeSpan.FromMinutes(2);
// Renew the lease.
ILease myLease = (ILease)mySponsor.InitializeLifetimeService();
TimeSpan myTime = mySponsor.Renewal(myLease);
Console.WriteLine("Renewed time in minutes is " + myTime.Minutes.ToString());
// Call the remote method.
Console.WriteLine(myService.HelloMethod("World"));
// Unregister the channel.
mySponsor.Unregister(myService);
mySponsor.Close();
}
}
}
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports System.Runtime.Remoting.Lifetime
Namespace RemotingSamples
Class HelloClient
Shared Sub Main()
' Register a channel.
Dim myChannel As New TcpChannel()
ChannelServices.RegisterChannel(myChannel)
RemotingConfiguration.RegisterActivatedClientType( _
GetType(HelloService), "tcp://localhost:8085")
' Get the remote object.
Dim myService As New HelloService()
' Get a sponsor for renewal of time.
Dim mySponsor As New ClientSponsor()
' Register the service with sponsor.
mySponsor.Register(myService)
' Set renewaltime.
mySponsor.RenewalTime = TimeSpan.FromMinutes(2)
' Renew the lease.
Dim myLease As ILease = CType(mySponsor.InitializeLifetimeService(), ILease)
Dim myTime As TimeSpan = mySponsor.Renewal(myLease)
Console.WriteLine("Renewed time in minutes is " & myTime.Minutes)
' Call the remote method.
Console.WriteLine(myService.HelloMethod("World"))
' Unregister the channel.
mySponsor.Unregister(myService)
mySponsor.Close()
End Sub
End Class
End Namespace 'RemotingSamples
Comentarios
La implementación actual del patrocinador de duración se puede usar para patrocinar objetos especificando la renovación TimeSpannecesaria.
Nota:
Esta clase realiza una demanda de vínculo y una demanda de herencia en el nivel de clase. SecurityException Se produce una excepción cuando el llamador inmediato o la clase derivada no tiene permiso de infraestructura.
Constructores
| Nombre | Description |
|---|---|
| ClientSponsor() |
Inicializa una nueva instancia de la ClientSponsor clase con valores predeterminados. |
| ClientSponsor(TimeSpan) |
Inicializa una nueva instancia de la ClientSponsor clase con el tiempo de renovación del objeto patrocinado. |
Propiedades
| Nombre | Description |
|---|---|
| RenewalTime |
Obtiene o establece el objeto por el TimeSpan que se aumenta la duración de los objetos patrocinados cuando se solicita la renovación. |
Métodos
| Nombre | Description |
|---|---|
| Close() |
Vacía los objetos de lista registrados con el objeto actual ClientSponsor. |
| CreateObjRef(Type) |
Crea un objeto que contiene toda la información pertinente necesaria para generar un proxy usado para comunicarse con un objeto remoto. (Heredado de MarshalByRefObject) |
| Equals(Object) |
Determina si el objeto especificado es igual que el objeto actual. (Heredado de Object) |
| Finalize() |
Libera los recursos del actual ClientSponsor antes de que el recolector de elementos no utilizados los recupere. |
| GetHashCode() |
Sirve como función hash predeterminada. (Heredado de Object) |
| GetLifetimeService() |
Obsoletos.
Recupera el objeto de servicio de duración actual que controla la directiva de duración de esta instancia. (Heredado de MarshalByRefObject) |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| InitializeLifetimeService() |
Inicializa una nueva instancia de ClientSponsor, proporcionando una concesión para el objeto actual. |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| MemberwiseClone(Boolean) |
Crea una copia superficial del objeto actual MarshalByRefObject . (Heredado de MarshalByRefObject) |
| Register(MarshalByRefObject) |
Registra el especificado MarshalByRefObject para el patrocinio. |
| Renewal(ILease) |
Solicita a un cliente patrocinador que renueve la concesión del objeto especificado. |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |
| Unregister(MarshalByRefObject) |
Anula el registro especificado MarshalByRefObject de la lista de objetos patrocinados por el objeto actual ClientSponsor. |