Export (0) Print
Expand All

IMethodMessage Interface

Defines the method message interface.

For a list of all members of this type, see IMethodMessage Members.

System.Runtime.Remoting.Messaging.IMessage
   System.Runtime.Remoting.Messaging.IMethodMessage

[Visual Basic]
Public Interface IMethodMessage
   Inherits IMessage
[C#]
public interface IMethodMessage : IMessage
[C++]
public __gc __interface IMethodMessage : public IMessage
[JScript]
public interface IMethodMessage implements IMessage

Classes that Implement IMethodMessage

Class Description
ReturnMessage Holds a message returned in response to a method call on a remote object.

Remarks

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.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
Public Class MyProxyClass
   Inherits RealProxy
   Private myObjectInstance As Object = Nothing
   Private myType As Type = Nothing
   
   Public Sub New(argType As Type)
      MyBase.New(argType)
      myType = argType
      myObjectInstance = Activator.CreateInstance(argType)
   End Sub 'New
   
   ' Overriding the Invoke method of RealProxy.
   Public Overrides Function Invoke(message As IMessage) As IMessage
      Dim myMethodMessage As IMethodMessage = CType(message, IMethodMessage)
      
      Console.WriteLine("**** Begin Invoke ****")
      Console.WriteLine(ControlChars.Tab + "Type is : " + myType.ToString())
      Console.WriteLine(ControlChars.Tab + "Method name : " + myMethodMessage.MethodName)
      
      Dim i As Integer
      For i = 0 To myMethodMessage.ArgCount - 1
         Console.WriteLine(ControlChars.Tab + "ArgName is : " + myMethodMessage.GetArgName(i))
         Console.WriteLine(ControlChars.Tab + "ArgValue is: " + myMethodMessage.GetArg(i))
      Next i
      
      If myMethodMessage.HasVarArgs Then
         Console.WriteLine(ControlChars.Tab + " The method have variable arguments!!")
      Else
         Console.WriteLine(ControlChars.Tab + " The method does not have variable arguments!!")
      End If 
      ' Dispatch the method call to the real object.
      Dim returnValue As Object = myType.InvokeMember(myMethodMessage.MethodName, _
                     BindingFlags.InvokeMethod, Nothing, myObjectInstance, myMethodMessage.Args)
      Console.WriteLine("**** End Invoke ****")
      
      ' Build the return message to pass back to the transparent proxy.
      Dim myReturnMessage As New ReturnMessage(returnValue, Nothing, 0, Nothing, _
                                                         CType(message, IMethodCallMessage))
      Return myReturnMessage
   End Function 'Invoke
End Class 'MyProxyClass

[C#] 
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;
   }
}

[C++] 
public __gc class MyProxyClass : public RealProxy 
{
private:
    Object* myObjectInstance;
private:
    Type* myType;

public:
    MyProxyClass(Type* argType) : RealProxy(argType) 
    {
        myType = argType;
        myObjectInstance = Activator::CreateInstance(argType);
    }

    // Overriding the Invoke method of RealProxy.
public:
    IMessage* Invoke(IMessage* message) 
    {
        IMethodMessage* myMethodMessage = dynamic_cast<IMethodMessage*>(message);

        Console::WriteLine(S"**** Begin Invoke ****");
        Console::WriteLine(S"\tType is : {0}", myType);
        Console::WriteLine(S"\tMethod name : {0}", myMethodMessage->MethodName);

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

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

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Runtime.Remoting.Messaging

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

IMethodMessage Members | System.Runtime.Remoting.Messaging Namespace

Show:
© 2014 Microsoft