ClientSponsor Class

ClientSponsor Class

 

Provides a default implementation for a lifetime sponsor class.

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

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

[SecurityCriticalAttribute]
[ComVisibleAttribute(true)]
[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, 
	Flags = SecurityPermissionFlag.Infrastructure)]
public class ClientSponsor : MarshalByRefObject, ISponsor

NameDescription
System_CAPS_pubmethodClientSponsor()

Initializes a new instance of the ClientSponsor class with default values.

System_CAPS_pubmethodClientSponsor(TimeSpan)

Initializes a new instance of the ClientSponsor class with the renewal time of the sponsored object.

NameDescription
System_CAPS_pubpropertyRenewalTime

Gets or sets the TimeSpan by which to increase the lifetime of the sponsored objects when renewal is requested.

NameDescription
System_CAPS_pubmethodClose()

Empties the list objects registered with the current ClientSponsor.

System_CAPS_pubmethodCreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Frees the resources of the current ClientSponsor before the garbage collector reclaims them.(Overrides Object.Finalize().)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

Initializes a new instance of ClientSponsor, providing a lease for the current object.(Overrides MarshalByRefObject.InitializeLifetimeService().)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodRegister(MarshalByRefObject)

Registers the specified MarshalByRefObject for sponsorship.

System_CAPS_pubmethodRenewal(ILease)

Requests a sponsoring client to renew the lease for the specified object.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodUnregister(MarshalByRefObject)

Unregisters the specified MarshalByRefObject from the list of objects sponsored by the current ClientSponsor.

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

System_CAPS_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.

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();
      }
   }

}

SecurityPermission

for operating with infrastructure code. Demand value: SecurityAction.LinkDemand; Permission Value: SecurityPermissionFlag.Infrastructure

SecurityPermission

for operating with infrastructure code. Demand value: SecurityAction.InheritanceDemand; Permission Value: SecurityPermissionFlag.Infrastructure

.NET Framework
Available since 1.1

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

Return to top
Show:
© 2016 Microsoft