ClientSponsor ClientSponsor ClientSponsor ClientSponsor Class

Definición

Proporciona una implementación predeterminada para una clase de patrocinador del período de duración.Provides a default implementation for a lifetime sponsor class.

public ref 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
Public Class ClientSponsor
Inherits MarshalByRefObject
Implements ISponsor
Herencia
Atributos
Implementaciones

Ejemplos

En el ejemplo siguiente se muestra la clase ClientSponsor para extender la duración de un objeto remoto activado en clases.The following example illustrates the ClientSponsor class to extend the life of a class-activated remote object.

#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 'Main
   End Class 'HelloClient


End Namespace 'RemotingSamples

Comentarios

La implementación del patrocinador de la duración actual se puede usar para patrocinar objetos mediante TimeSpanla especificación de la renovación necesaria.The current lifetime sponsor implementation can be used to sponsor objects by specifying the required renewal TimeSpan.

Nota

Esta clase realiza una petición de vínculo y una petición de herencia en el nivel de clase.This class makes a link demand and an inheritance demand at the class level. Se SecurityException produce una excepción cuando el llamador inmediato o la clase derivada no tienen permiso de infraestructura.A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. Para obtener más información sobre las demandas de seguridad, consulte peticiones de vínculo y peticiones de herencia.For details about security demands, see Link Demands and Inheritance Demands.

Constructores

ClientSponsor() ClientSponsor() ClientSponsor() ClientSponsor()

Inicializa una nueva instancia de la clase ClientSponsor con valores predeterminados.Initializes a new instance of the ClientSponsor class with default values.

ClientSponsor(TimeSpan) ClientSponsor(TimeSpan) ClientSponsor(TimeSpan) ClientSponsor(TimeSpan)

Inicializa una nueva instancia de la clase ClientSponsor con el tiempo de renovación del objeto patrocinado.Initializes a new instance of the ClientSponsor class with the renewal time of the sponsored object.

Propiedades

RenewalTime RenewalTime RenewalTime RenewalTime

Obtiene o establece el TimeSpan en que se amplía el período de duración de los objetos patrocinados cuando se solicita una renovación.Gets or sets the TimeSpan by which to increase the lifetime of the sponsored objects when renewal is requested.

Métodos

Close() Close() Close() Close()

Vacía la lista de objetos registrados con el ClientSponsor actual.Empties the list objects registered with the current ClientSponsor.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Crea un objeto que contiene toda la información relevante necesaria para generar un proxy utilizado para comunicarse con un objeto remoto.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

Libera los recursos del ClientSponsor actual antes de que los reclame el recolector de elementos no utilizados.Frees the resources of the current ClientSponsor before the garbage collector reclaims them.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Recupera el objeto de servicio de duración actual que controla la directiva de duración de esta instancia.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Inicializa una nueva instancia de ClientSponsor, que proporciona una concesión para el objeto actual.Initializes a new instance of ClientSponsor, providing a lease for the current object.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Crea una copia superficial del objeto MarshalByRefObject actual.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Register(MarshalByRefObject) Register(MarshalByRefObject) Register(MarshalByRefObject) Register(MarshalByRefObject)

Registra el MarshalByRefObject especificado para el patrocinio.Registers the specified MarshalByRefObject for sponsorship.

Renewal(ILease) Renewal(ILease) Renewal(ILease) Renewal(ILease)

Solicita un cliente patrocinador para renovar el período del objeto especificado.Requests a sponsoring client to renew the lease for the specified object.

ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)
Unregister(MarshalByRefObject) Unregister(MarshalByRefObject) Unregister(MarshalByRefObject) Unregister(MarshalByRefObject)

Anula el registro del MarshalByRefObject especificado en la lista de objetos patrocinados por el ClientSponsor actual.Unregisters the specified MarshalByRefObject from the list of objects sponsored by the current ClientSponsor.

Seguridad

SecurityPermission
para trabajar con código de infraestructura.for operating with infrastructure code. Valor de petición InheritanceDemand:; Valor de permiso:InfrastructureDemand value: InheritanceDemand; Permission Value: Infrastructure

Se aplica a