ClientSponsor Sınıf

Tanım

Yaşam süresi sponsor sınıfı için varsayılan bir uygulama sağlar.

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
Devralma
ClientSponsor
Öznitelikler
Uygulamalar

Örnekler

Aşağıdaki örnekte, sınıf etkinleştirilmiş uzak nesnenin ömrünü uzatmak için ClientSponsor sınıfı gösterilmektedir.

#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

Açıklamalar

Geçerli yaşam süresi sponsoru uygulaması, gerekli yenilemeyi TimeSpanbelirterek nesneleri desteklemek için kullanılabilir.

Not

Bu sınıf, sınıf düzeyinde bir bağlantı talebi ve devralma talebi oluşturur. Hemen SecurityException çağıranın veya türetilen sınıfın altyapı izni olmadığında oluşturulur. Güvenlik talepleri hakkında ayrıntılı bilgi için bkz. Talepler ve Devralma Taleplerini Bağlama.

Oluşturucular

ClientSponsor()

ClientSponsor sınıfının yeni bir örneğini varsayılan değerlerle başlatır.

ClientSponsor(TimeSpan)

Sponsorlu nesnenin ClientSponsor yenileme süresiyle sınıfının yeni bir örneğini başlatır.

Özellikler

RenewalTime

Yenileme istendiğinde sponsorlu nesnelerin ömrünün hangi şekilde artıracağını alır veya ayarlar TimeSpan .

Yöntemler

Close()

Geçerli ClientSponsorile kaydedilen liste nesnelerini boşaltın.

CreateObjRef(Type)

Uzak bir nesneyle iletişim kurmak için kullanılan bir ara sunucu oluşturmak için gereken tüm ilgili bilgileri içeren bir nesne oluşturur.

(Devralındığı yer: MarshalByRefObject)
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
Finalize()

Atık toplayıcı geri kazanmadan önce geçerli ClientSponsor kaynakları serbest.

GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetLifetimeService()
Geçersiz.

Bu örnek için yaşam süresi ilkesini denetleen geçerli yaşam süresi hizmet nesnesini alır.

(Devralındığı yer: MarshalByRefObject)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
InitializeLifetimeService()

Geçerli nesne için kira sağlayan yeni bir örneğini ClientSponsorbaşlatır.

MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
MemberwiseClone(Boolean)

Geçerli MarshalByRefObject nesnenin sığ bir kopyasını oluşturur.

(Devralındığı yer: MarshalByRefObject)
Register(MarshalByRefObject)

Belirtilen MarshalByRefObject sponsorluğu kaydeder.

Renewal(ILease)

Bir sponsor istemciden belirtilen nesnenin kirasını yenilemesini istemektedir.

ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)
Unregister(MarshalByRefObject)

Geçerli ClientSponsortarafından desteklenen nesneler listesinden belirtilenlerin MarshalByRefObject kaydını kaldırır.

Şunlara uygulanır