RemotingServices.GetSessionIdForMethodMessage Method

Retrieves a session ID for a message.

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

public static string GetSessionIdForMethodMessage(
	IMethodMessage msg
)

Parameters

msg
Type: System.Runtime.Remoting.Messaging.IMethodMessage

The IMethodMessage for which a session ID is requested.

Return Value

Type: System.String
A session ID string that uniquely identifies the current session.

ExceptionCondition
SecurityException

The immediate caller does not have infrastructure permission.

The same session ID might be returned for objects in the same application, but this method will never return the same session ID for two objects in different remote applications.

For more information about identifying sessions and session IDs, see ASP.Net ASP.NET Session State Overview.

The following code example demonstrates how to get the session ID string for the current session.

[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
public void ProcessMessageStart(IMessage requestMessage, bool bClientSide, bool bAsyncCall) {

   Console.WriteLine("\nProcessMessageStart");
   Console.WriteLine("requestMessage = {0}", requestMessage);

   try {
      Console.WriteLine("SessionId = {0}.",
          RemotingServices.GetSessionIdForMethodMessage((IMethodMessage)requestMessage));
   }
   catch (InvalidCastException) {
      Console.WriteLine("The requestMessage is not an IMethodMessage.");
   }

   IMethodCallMessage requestMethodCallMessage;

   try {
      requestMethodCallMessage = (IMethodCallMessage)requestMessage;
      // Prints the details of the IMethodCallMessage to the console.
      Console.WriteLine("\nMethodCall details");
      Console.WriteLine("Uri = {0}", requestMethodCallMessage.Uri);
      Console.WriteLine("TypeName = {0}", requestMethodCallMessage.TypeName);
      Console.WriteLine("MethodName = {0}", requestMethodCallMessage.MethodName);
      Console.WriteLine("ArgCount = {0}", requestMethodCallMessage.ArgCount);

      Console.WriteLine("MethodCall.Args");
      foreach(object o in requestMethodCallMessage.Args)
          Console.WriteLine("\t{0}", o);

      // Sends this method call message to another server to replicate 
      // the call at the second server. 
      if (requestMethodCallMessage.Uri == replicatedServiceUri) {

         SampleService replicationService = 
            (SampleService)Activator.GetObject(typeof(SampleService), 
            replicationServerUrl + replicatedServiceUri);

         IMethodReturnMessage returnMessage = 
            RemotingServices.ExecuteMessage(replicationService, requestMethodCallMessage);

         // Prints the results of the method call stored in the IMethodReturnMessage.
         Console.WriteLine("\nMessage returned by ExecuteMessage.");
         Console.WriteLine("\tException = {0}", returnMessage.Exception);
         Console.WriteLine("\tReturnValue = {0}", returnMessage.ReturnValue);
         Console.WriteLine("\tOutArgCount = {0}", returnMessage.OutArgCount);
         Console.WriteLine("Return message OutArgs");

         foreach(object o in requestMethodCallMessage.Args)
            Console.WriteLine("\t{0}", o);
      }
   }
   catch (InvalidCastException) {
       Console.WriteLine("The requestMessage is not a MethodCall");
   }
}

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft