Export (0) Print
Expand All

ClientSponsor Class

Provides a default implementation for a lifetime sponsor class.

Namespace:  System.Runtime.Remoting.Lifetime
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<ComVisibleAttribute(True)> _
<SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
<SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.Infrastructure)> _
Public Class ClientSponsor _
	Inherits MarshalByRefObject _
	Implements ISponsor
'Usage
Dim instance As ClientSponsor

The current lifetime sponsor implementation can be used to sponsor objects by specifying the required renewal TimeSpan.

NoteNote:

This class makes a link demand and an inheritance demand at the class level. A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see Link Demands and Inheritance Demands.

The following example illustrates the ClientSponsor class to extend the life of a class-activated remote object.

Imports System
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 'Main
   End Class 'HelloClient


End Namespace 'RemotingSamples
#using <mscorlib.dll>
#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 = new TcpChannel();
	ChannelServices::RegisterChannel(myChannel);
	RemotingConfiguration::RegisterActivatedClientType(__typeof(RemotingSamples::HelloService), S"tcp://localhost:8085/");

	// Get the remote Object*.
	RemotingSamples::HelloService* myService = new RemotingSamples::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 = dynamic_cast<ILease*>(mySponsor->InitializeLifetimeService());
	TimeSpan myTime = mySponsor->Renewal(myLease);
	Console::WriteLine(S"Renewed time in minutes is {0}", __box(myTime.Minutes));

	// Call the remote method.
	Console::WriteLine(myService->HelloMethod(S"World"));

	// Unregister the channel.
	mySponsor->Unregister(myService);
	mySponsor->Close();

	return 0;
}

System.Object
  System.MarshalByRefObject
    System.Runtime.Remoting.Lifetime.ClientSponsor

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft