Export (0) Print
Expand All

CallContext.GetData Method

Retrieves an object with the specified name from the CallContext.

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

public static Object GetData(
	string name
)

Parameters

name
Type: System.String

The name of the item in the call context.

Return Value

Type: System.Object
The object in the call context associated with the specified name.

ExceptionCondition
SecurityException

The immediate caller does not have infrastructure permission.

The following code example demonstrates the use of the GetData method to transmit Principal and Identity Objects to a remote location for identification. To view the code for the LogicalCallContextData class used in this sample, see the example for the ILogicalThreadAffinative interface. To view the code for the client class used in the sample, see the example for the CallContext class. To view the code for the server class used in this sample, see the example for the RegisterActivatedServiceType class.

using System;
using System.Text;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Security.Permissions;

public class HelloServiceClass : MarshalByRefObject {

   static int n_instances;
   int instanceNum;

   public HelloServiceClass() {
      n_instances++;
      instanceNum = n_instances;
      Console.WriteLine(this.GetType().Name + " has been created.  Instance # = {0}", instanceNum);
   }


   ~HelloServiceClass() {
      Console.WriteLine("Destroyed instance {0} of HelloServiceClass.", instanceNum);      
   }


   [PermissionSet(SecurityAction.LinkDemand)]
   public String HelloMethod(String name) {

      //Extract the call context data
      LogicalCallContextData data = (LogicalCallContextData)CallContext.GetData("test data");      
      IPrincipal myPrincipal = data.Principal;

      //Check the user identity 
      if(myPrincipal.Identity.Name == "Bob") {
         Console.WriteLine("\nHello {0}, you are identified!", myPrincipal.Identity.Name);
         Console.WriteLine(data.numOfAccesses);
      }
      else {
         Console.WriteLine("Go away! You are not identified!");
         return String.Empty;
      }

        // calculate and return result to client	 
      return "Hi there " + name + ".";
   }
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft