ClientSponsor ClientSponsor ClientSponsor ClientSponsor Class

Definizione

Fornisce un'implementazione predefinita per una classe di sponsor di durata.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
Ereditarietà
Attributi
Implementazioni

Esempi

Nell'esempio seguente viene illustrata la classe ClientSponsor per estendere la durata di un oggetto remoto attivato dalla classe.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

Commenti

Per sponsorizzare gli oggetti, è possibile usare l'implementazione del garante della durata corrente TimeSpanspecificando il rinnovo richiesto.The current lifetime sponsor implementation can be used to sponsor objects by specifying the required renewal TimeSpan.

Nota

Questa classe esegue una richiesta di collegamento e una richiesta di ereditarietà a livello di classe.This class makes a link demand and an inheritance demand at the class level. Viene SecurityException generata un'eccezione quando il chiamante immediato o la classe derivata non dispone dell'autorizzazione di infrastruttura.A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. Per informazioni dettagliate sulle richieste di sicurezza, vedere richieste di collegamento e richieste di ereditarietà.For details about security demands, see Link Demands and Inheritance Demands.

Costruttori

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

Inizializza una nuova istanza della classe ClientSponsor con i valori predefiniti.Initializes a new instance of the ClientSponsor class with default values.

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

Inizializza una nuova istanza della classe ClientSponsor con il tempo di rinnovo dell'oggetto sponsorizzato.Initializes a new instance of the ClientSponsor class with the renewal time of the sponsored object.

Proprietà

RenewalTime RenewalTime RenewalTime RenewalTime

Ottiene o imposta il TimeSpan di cui aumentare la durata degli oggetti sponsorizzati quando è richiesto il rinnovo.Gets or sets the TimeSpan by which to increase the lifetime of the sponsored objects when renewal is requested.

Metodi

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

Svuota l'elenco di oggetti registrati nella classe ClientSponsor corrente.Empties the list objects registered with the current ClientSponsor.

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

Consente di creare un oggetto che contiene tutte le informazioni rilevanti necessarie per la generazione del proxy utilizzato per effettuare la comunicazione con un oggetto 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 se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

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

Libera le risorse della classe ClientSponsor corrente prima che vengano reclamate dal Garbage Collector.Frees the resources of the current ClientSponsor before the garbage collector reclaims them.

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

Funge da funzione hash predefinita.Serves as the default hash function.

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

Consente di recuperare l'oggetto servizio di durata corrente per controllare i criteri di durata per l'istanza.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

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

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

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

Inizializza una nuova istanza di ClientSponsor, fornendo un lease per l'oggetto corrente.Initializes a new instance of ClientSponsor, providing a lease for the current object.

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

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

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

Crea una copia dei riferimenti dell'oggetto MarshalByRefObject corrente.Creates a shallow copy of the current MarshalByRefObject object.

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

Registra l'oggetto MarshalByRefObject specificato per la sponsorizzazione.Registers the specified MarshalByRefObject for sponsorship.

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

Chiede a un client sponsor di rinnovare il lease per l'oggetto specificato.Requests a sponsoring client to renew the lease for the specified object.

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

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

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

Annulla la registrazione dell'oggetto MarshalByRefObject specificato dall'elenco di oggetti sponsorizzati dal ClientSponsor corrente.Unregisters the specified MarshalByRefObject from the list of objects sponsored by the current ClientSponsor.

Sicurezza

SecurityPermission
per l'utilizzo del codice dell'infrastruttura.for operating with infrastructure code. Valore richiesta: InheritanceDemand; Valore autorizzazione:InfrastructureDemand value: InheritanceDemand; Permission Value: Infrastructure

Si applica a