GetData Method
Collapse the table of content
Expand the table of content

CallContext.GetData Method (String)


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


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.

Exception Condition

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() {
      instanceNum = n_instances;
      Console.WriteLine(this.GetType().Name + " has been created.  Instance # = {0}", instanceNum);

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

   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);
      else {
         Console.WriteLine("Go away! You are not identified!");
         return String.Empty;

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


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

.NET Framework
Available since 1.1
Return to top
© 2016 Microsoft