ClientSponsor Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Fournit une implémentation par défaut pour une classe de sponsor de durée de vie.
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
- Héritage
- Attributs
- Implémente
Exemples
L’exemple suivant illustre la classe ClientSponsor pour prolonger la durée de vie d’un objet distant activé par une classe.
#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
Remarques
L’implémentation actuelle du sponsor de durée de vie peut être utilisée pour parrainer des objets en spécifiant le renouvellement TimeSpanrequis.
Note
Cette classe effectue une demande de liaison et une demande d’héritage au niveau de la classe. A SecurityException est levée lorsque l’appelant immédiat ou la classe dérivée n’a pas d’autorisation d’infrastructure.
Constructeurs
| Nom | Description |
|---|---|
| ClientSponsor() |
Initialise une nouvelle instance de la ClientSponsor classe avec des valeurs par défaut. |
| ClientSponsor(TimeSpan) |
Initialise une nouvelle instance de la ClientSponsor classe avec l’heure de renouvellement de l’objet parrainé. |
Propriétés
| Nom | Description |
|---|---|
| RenewalTime |
Obtient ou définit la TimeSpan durée de vie des objets parrainés lorsque le renouvellement est demandé. |
Méthodes
| Nom | Description |
|---|---|
| Close() |
Vide les objets de liste inscrits avec le fichier actif ClientSponsor. |
| CreateObjRef(Type) |
Crée un objet qui contient toutes les informations pertinentes requises pour générer un proxy utilisé pour communiquer avec un objet distant. (Hérité de MarshalByRefObject) |
| Equals(Object) |
Détermine si l'objet spécifié est identique à l'objet actuel. (Hérité de Object) |
| Finalize() |
Libère les ressources du garbage ClientSponsor collector avant que le garbage collector ne les récupère. |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetLifetimeService() |
Obsolète.
Récupère l’objet de service de durée de vie actuel qui contrôle la stratégie de durée de vie de cette instance. (Hérité de MarshalByRefObject) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| InitializeLifetimeService() |
Initialise une nouvelle instance de ClientSponsor, en fournissant un bail pour l’objet actuel. |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| MemberwiseClone(Boolean) |
Crée une copie superficielle de l’objet actuel MarshalByRefObject . (Hérité de MarshalByRefObject) |
| Register(MarshalByRefObject) |
Inscrit le parrainage spécifié MarshalByRefObject . |
| Renewal(ILease) |
Demande à un client parrain de renouveler le bail pour l’objet spécifié. |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |
| Unregister(MarshalByRefObject) |
Annule l’inscription spécifiée MarshalByRefObject à partir de la liste des objets parrainés par le fichier actif ClientSponsor. |