ClientSponsor Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Fornisce un'implementazione predefinita per una classe sponsor di durata.
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
- Ereditarietà
- Attributi
- Implementazioni
Esempio
Nell'esempio seguente viene illustrata la classe ClientSponsor per estendere la durata di un oggetto remoto attivato dalla 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
Commenti
L'implementazione dello sponsor della durata corrente può essere usata per sponsorizzare gli oggetti specificando il rinnovo TimeSpanrichiesto.
Annotazioni
Questa classe effettua una richiesta di collegamento e una richiesta di ereditarietà a livello di classe. Viene SecurityException generata un'eccezione quando il chiamante immediato o la classe derivata non dispone dell'autorizzazione dell'infrastruttura. Per informazioni dettagliate sulle richieste di sicurezza, vedere Richieste di collegamento.
Costruttori
| Nome | Descrizione |
|---|---|
| ClientSponsor() |
Inizializza una nuova istanza della ClientSponsor classe con valori predefiniti. |
| ClientSponsor(TimeSpan) |
Inizializza una nuova istanza della ClientSponsor classe con l'ora di rinnovo dell'oggetto sponsorizzato. |
Proprietà
| Nome | Descrizione |
|---|---|
| RenewalTime |
Ottiene o imposta l'oggetto TimeSpan in base al quale aumentare la durata degli oggetti sponsorizzati quando viene richiesto il rinnovo. |
Metodi
| Nome | Descrizione |
|---|---|
| Close() |
Svuota gli oggetti elenco registrati con l'oggetto corrente ClientSponsor. |
| CreateObjRef(Type) |
Crea un oggetto che contiene tutte le informazioni pertinenti necessarie per generare un proxy utilizzato per comunicare con un oggetto remoto. (Ereditato da MarshalByRefObject) |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| Finalize() |
Libera le risorse dell'oggetto corrente ClientSponsor prima che vengano recuperate dal Garbage Collector. |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetLifetimeService() |
Obsoleti.
Recupera l'oggetto servizio di durata corrente che controlla i criteri di durata per questa istanza. (Ereditato da MarshalByRefObject) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| InitializeLifetimeService() |
Inizializza una nuova istanza di ClientSponsor, fornendo un lease per l'oggetto corrente. |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| MemberwiseClone(Boolean) |
Crea una copia superficiale dell'oggetto corrente MarshalByRefObject . (Ereditato da MarshalByRefObject) |
| Register(MarshalByRefObject) |
Registra l'oggetto specificato MarshalByRefObject per la sponsorizzazione. |
| Renewal(ILease) |
Richiede a un client sponsor di rinnovare il lease per l'oggetto specificato. |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
| Unregister(MarshalByRefObject) |
Annulla la registrazione dell'oggetto specificato MarshalByRefObject dall'elenco di oggetti sponsorizzati dall'oggetto corrente ClientSponsor. |