ClientSponsor Třída

Definice

Poskytuje výchozí implementaci pro třídu sponzora životnosti.

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
Dědičnost
ClientSponsor
Atributy
Implementuje

Příklady

Následující příklad znázorňuje třídu ClientSponsor pro prodloužení životnosti vzdáleného objektu aktivovaného třídou.

#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

Poznámky

Aktuální implementaci sponzora životnosti lze použít k sponzorování objektů zadáním požadovaného prodloužení TimeSpan.

Poznámka

Tato třída vytváří požadavek na propojení a požadavek dědičnosti na úrovni třídy. Vyvolá SecurityException se, když buď okamžitý volající, nebo odvozená třída nemá oprávnění infrastruktury. Podrobnosti o požadavcích na zabezpečení najdete v tématu Požadavky na propojení a požadavky dědičnosti.

Konstruktory

ClientSponsor()

Inicializuje novou instanci třídy ClientSponsor s výchozími hodnotami.

ClientSponsor(TimeSpan)

Inicializuje novou instanci ClientSponsor třídy s časem prodloužení sponzorovaného objektu.

Vlastnosti

RenewalTime

Získá nebo nastaví TimeSpan , o který se má zvýšit životnost sponzorovaných objektů při žádosti o prodloužení.

Metody

Close()

Vyprázdní objekty seznamu zaregistrované v aktuálním ClientSponsorobjektu .

CreateObjRef(Type)

Vytvoří objekt, který obsahuje všechny relevantní informace potřebné k vygenerování proxy serveru používaného ke komunikaci se vzdáleným objektem.

(Zděděno od MarshalByRefObject)
Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
Finalize()

Uvolní prostředky aktuálního stavu ClientSponsor , než je uvolňování paměti uvolní.

GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetLifetimeService()
Zastaralé.

Načte aktuální objekt služby životnosti, který řídí zásady životnosti pro tuto instanci.

(Zděděno od MarshalByRefObject)
GetType()

Type Získá aktuální instanci.

(Zděděno od Object)
InitializeLifetimeService()

Inicializuje novou instanci ClientSponsor, poskytuje zapůjčení pro aktuální objekt.

MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
MemberwiseClone(Boolean)

Vytvoří kopii aktuálního objektu bez MarshalByRefObject podmět.

(Zděděno od MarshalByRefObject)
Register(MarshalByRefObject)

Zaregistruje zadanou MarshalByRefObject nabídku Sponsorship.

Renewal(ILease)

Požádá sponzorujícího klienta o prodloužení zapůjčení pro zadaný objekt.

ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)
Unregister(MarshalByRefObject)

Zruší registraci zadaného MarshalByRefObject ze seznamu objektů sponzorovaných aktuálním ClientSponsor.

Platí pro