ClientSponsor Klasse

Definition

Stellt eine Standardimplementierung für eine Lebendsdauersponsor-Klasse 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 von der Klasse aktivierten Remoteobjekts zu verlängern.

#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 Sponsorimplementierung für die Lebensdauer kann verwendet werden, um Objekte zu sponsern, indem die erforderliche Verlängerung TimeSpanangegeben wird.

Hinweis

Diese Klasse stellt eine Linkanforderung und eine Vererbungsanforderung auf Klassenebene her. Ein SecurityException wird ausgelöst, wenn entweder der unmittelbare Aufrufer oder die abgeleitete Klasse über keine Infrastrukturberechtigung verfügt. Ausführliche Informationen zu Sicherheitsanforderungen finden Sie unter Linkanforderungen und Vererbungsanforderungen.

Konstruktoren

ClientSponsor()

Initialisiert eine neue Instanz der ClientSponsor-Klasse mit Standardwerten.

ClientSponsor(TimeSpan)

Initialisiert eine neue Instanz der ClientSponsor-Klasse mit der Erneuerungszeit des Objekts mit Sponsor.

Eigenschaften

RenewalTime

Ruft die TimeSpan ab, um die die Lebensdauer der Objekte mit Sponsor bei Anforderung einer Erneuerung erhöht werden soll, oder legt diese fest.

Methoden

Close()

Leert die Listenobjekte, die im aktuellen ClientSponsor registriert sind.

CreateObjRef(Type)

Erstellt ein Objekt mit allen relevanten Informationen, die zum Generieren eines Proxys für die Kommunikation mit einem Remoteobjekt erforderlich sind.

(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 sie vom Garbage Collector freigegeben werden.

GetHashCode()

Fungiert als Standardhashfunktion.

(Geerbt von Object)
GetLifetimeService()
Veraltet.

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

(Geerbt von MarshalByRefObject)
GetType()

Ruft den Type der aktuellen Instanz ab.

(Geerbt von Object)
InitializeLifetimeService()

Initialisiert eine neue Instanz von ClientSponsor, die einen Lease für das aktuelle Objekt enthält.

MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.

(Geerbt von Object)
MemberwiseClone(Boolean)

Erstellt eine flache Kopie des aktuellen MarshalByRefObject-Objekts.

(Geerbt von MarshalByRefObject)
Register(MarshalByRefObject)

Registriert das angegebene MarshalByRefObject für Sponsorschaft.

Renewal(ILease)

Fordert von einem Sponsorclient eine Erneuerung des Lease für das angegebene Objekt an.

ToString()

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

(Geerbt von Object)
Unregister(MarshalByRefObject)

Hebt die Registrierung des angegebenen MarshalByRefObject in der Liste der Objekte auf, die vom aktuellen ClientSponsor gesponsert werden.

Gilt für: