ClientSponsor Classe
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Fornece uma implementação padrão para uma classe de patrocinador vitalício.
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
- Herança
- Atributos
- Implementações
Exemplos
O exemplo seguinte ilustra a classe ClientSponsor para prolongar a vida de um objeto remoto ativado pela 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
Observações
A implementação atual do patrocinador vitalício pode ser usada para patrocinar objetos, especificando a renovação TimeSpannecessária.
Note
Esta classe cria uma exigência de ligação e uma exigência de herança ao nível da classe. A SecurityException é lançado quando o chamador imediato ou a classe derivada não têm permissão de infraestrutura. Para detalhes sobre exigências de segurança, consulte Exigências de Ligação e Exigências de Herança.
Construtores
| Name | Description |
|---|---|
| ClientSponsor() |
Inicializa uma nova instância da ClientSponsor classe com valores por defeito. |
| ClientSponsor(TimeSpan) |
Inicializa uma nova instância da ClientSponsor classe com a hora de renovação do objeto patrocinado. |
Propriedades
| Name | Description |
|---|---|
| RenewalTime |
Obtém ou define o TimeSpan prazo para aumentar a vida útil dos objetos patrocinados quando a renovação for solicitada. |
Métodos
| Name | Description |
|---|---|
| Close() |
Esvazia os objetos da lista registados com o atual ClientSponsor. |
| CreateObjRef(Type) |
Cria um objeto que contém toda a informação relevante necessária para gerar um proxy usado para comunicar com um objeto remoto. (Herdado de MarshalByRefObject) |
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
| Finalize() |
Liberta os recursos da corrente ClientSponsor antes que o coletor de lixo os recupere. |
| GetHashCode() |
Serve como função de hash predefinida. (Herdado de Object) |
| GetLifetimeService() |
Obsoleto.
Recupera o objeto de serviço de tempo de vida atual que controla a política de vida útil neste caso. (Herdado de MarshalByRefObject) |
| GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
| InitializeLifetimeService() |
Inicializa uma nova instância de ClientSponsor, fornecendo um arrendamento para o objeto atual. |
| MemberwiseClone() |
Cria uma cópia superficial do atual Object. (Herdado de Object) |
| MemberwiseClone(Boolean) |
Cria uma cópia superficial do objeto atual MarshalByRefObject . (Herdado de MarshalByRefObject) |
| Register(MarshalByRefObject) |
Regista o especificado MarshalByRefObject para patrocínio. |
| Renewal(ILease) |
Solicita a um cliente patrocinador a renovação do contrato de arrendamento do objeto especificado. |
| ToString() |
Devolve uma cadeia que representa o objeto atual. (Herdado de Object) |
| Unregister(MarshalByRefObject) |
Desregista o especificado MarshalByRefObject da lista de objetos patrocinados pelo atual ClientSponsor. |