Freigeben über


ClientSponsor Klasse

Definition

Stellt eine Standardimplementierung für eine lebenslange Sponsorklasse bereit.

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
Vererbung
ClientSponsor
Attribute
Implementiert

Beispiele

Im folgenden Beispiel wird die ClientSponsor-Klasse veranschaulicht, um die Lebensdauer eines klassenaktivierten Remoteobjekts zu erweitern.

#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

Hinweise

Die aktuelle Implementierung des Lebenszyklussponsors kann zum Sponsoren von Objekten verwendet werden, indem die erforderliche Erneuerung TimeSpanangegeben wird.

Hinweis

Diese Klasse macht eine Verknüpfungsnachfrage und eine Vererbungsnachfrage auf Klassenebene. Ein SecurityException Fehler wird ausgelöst, wenn entweder der direkte Aufrufer oder die abgeleitete Klasse keine Infrastrukturberechtigung besitzt. Ausführliche Informationen zu Sicherheitsanforderungen finden Sie unter Linkanforderungen.

Konstruktoren

Name Beschreibung
ClientSponsor()

Initialisiert eine neue Instanz der ClientSponsor Klasse mit Standardwerten.

ClientSponsor(TimeSpan)

Initialisiert eine neue Instanz der ClientSponsor Klasse mit der Verlängerungszeit des gesponserten Objekts.

Eigenschaften

Name Beschreibung
RenewalTime

Ruft ab oder legt fest, TimeSpan um welche die Lebensdauer der gesponserten Objekte erhöht werden soll, wenn eine Verlängerung angefordert wird.

Methoden

Name Beschreibung
Close()

Leert die mit dem aktuellen Objekt registrierten ClientSponsorListenobjekte.

CreateObjRef(Type)

Erstellt ein Objekt, das alle relevanten Informationen enthält, die zum Generieren eines Proxys erforderlich sind, der für die Kommunikation mit einem Remoteobjekt verwendet wird.

(Geerbt von MarshalByRefObject)
Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
Finalize()

Gibt die Ressourcen des aktuellen ClientSponsor frei, bevor der Garbage Collector sie zurückgibt.

GetHashCode()

Dient als die Standard-Hashfunktion

(Geerbt von Object)
GetLifetimeService()
Veraltet.

Ruft das aktuelle Lebensdauerdienstobjekt ab, das die Lebensdauerrichtlinie für diese Instanz steuert.

(Geerbt von MarshalByRefObject)
GetType()

Ruft die Type der aktuellen Instanz ab.

(Geerbt von Object)
InitializeLifetimeService()

Initialisiert eine neue Instanz von ClientSponsor, die eine Lease für das aktuelle Objekt bereitstellt.

MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
MemberwiseClone(Boolean)

Erstellt eine flache Kopie des aktuellen MarshalByRefObject Objekts.

(Geerbt von MarshalByRefObject)
Register(MarshalByRefObject)

Registriert das angegebene MarshalByRefObject Sponsoring.

Renewal(ILease)

Fordert einen Sponsoring-Kunden auf, den Leasingvertrag für das angegebene Objekt zu verlängern.

ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.

(Geerbt von Object)
Unregister(MarshalByRefObject)

Hebt die Registrierung der angegebenen MarshalByRefObject Liste der Objekte auf, die von der aktuellen ClientSponsorWebsite gesponsert werden.

Gilt für: