Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

IMethodMessage Interface

Defines the method message interface.

Namespace:  System.Runtime.Remoting.Messaging
Assembly:  mscorlib (in mscorlib.dll)
[ComVisibleAttribute(true)]
public interface IMethodMessage : IMessage

The IMethodMessage type exposes the following members.

  NameDescription
Public propertyArgCountGets the number of arguments passed to the method.
Public propertyArgsGets an array of arguments passed to the method.
Public propertyHasVarArgsGets a value indicating whether the message has variable arguments.
Public propertyLogicalCallContextGets the LogicalCallContext for the current method call.
Public propertyMethodBaseGets the MethodBase of the called method.
Public propertyMethodNameGets the name of the invoked method.
Public propertyMethodSignatureGets an object containing the method signature.
Public propertyPropertiesGets an IDictionary that represents a collection of the message's properties. (Inherited from IMessage.)
Public propertyTypeNameGets the full Type name of the specific object that the call is destined for.
Public propertyUriGets the URI of the specific object that the call is destined for.
Top
  NameDescription
Public methodGetArgGets a specific argument as an Object.
Public methodGetArgNameGets the name of the argument passed to the method.
Top

A method message is used to send information to and from remote methods. For example, messages used for remote method calls implement the IMethodMessage interface.

The following example code shows a custom proxy that overrides RealProxy.Invoke in order to write the message information to the console and return immediately without making a remote call.


[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public class MyProxyClass : RealProxy
{
   private Object  myObjectInstance  = null;
   private Type    myType      = null;

   public MyProxyClass(Type argType) : base(argType)
   {
      myType = argType;
      myObjectInstance = Activator.CreateInstance(argType);
   }

   // Overriding the Invoke method of RealProxy.
   public override IMessage Invoke(IMessage message)
   {
      IMethodMessage myMethodMessage = (IMethodMessage)message;

      Console.WriteLine("**** Begin Invoke ****");
      Console.WriteLine("\tType is : " + myType);
      Console.WriteLine("\tMethod name : " +  myMethodMessage.MethodName);

      for (int i=0; i < myMethodMessage.ArgCount; i++)
      {
         Console.WriteLine("\tArgName is : " + myMethodMessage.GetArgName(i));
         Console.WriteLine("\tArgValue is: " + myMethodMessage.GetArg(i));
      }

      if(myMethodMessage.HasVarArgs)
          Console.WriteLine("\t The method have variable arguments!!");
      else
          Console.WriteLine("\t The method does not have variable arguments!!");

      // Dispatch the method call to the real object.
      Object returnValue = myType.InvokeMember( myMethodMessage.MethodName, BindingFlags.InvokeMethod, null,
                                           myObjectInstance, myMethodMessage.Args );
      Console.WriteLine("**** End Invoke ****");

      // Build the return message to pass back to the transparent proxy.
      ReturnMessage myReturnMessage = new ReturnMessage( returnValue, null, 0, null,
          (IMethodCallMessage)message );
      return myReturnMessage;
   }
}


.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.