Export (0) Print
Expand All

IMethodCallMessage Interface

Defines the method call message interface.

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

[ComVisibleAttribute(true)]
public interface IMethodCallMessage : IMethodMessage, 
	IMessage

An IMethodCallMessage is generated as a result of a method called on a remote object, and is used to transport details about the remote method call to the server side.

using System;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
using System.Security.Permissions;

namespace IMethodCallMessageNS
{
   // MyProxy extends the CLR Remoting RealProxy. 
   // In the same class, in the Invoke method, the methods and properties of the  
   // IMethodCallMessage are demonstrated.

   [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
   public class MyProxy : RealProxy
   {
      public MyProxy(Type myType) : base(myType)
      {
         // This constructor forwards the call to base RealProxy. 
         // RealProxy uses the Type to generate a transparent proxy.
      }


      public override IMessage Invoke(IMessage myIMessage)
      {
         Console.WriteLine("MyProxy.Invoke Start");
         Console.WriteLine("");
         ReturnMessage myReturnMessage = null;

         if (myIMessage is IMethodCallMessage)
         {
            Console.WriteLine("Message is of type 'IMethodCallMessage'.");
            Console.WriteLine("");

            IMethodCallMessage myIMethodCallMessage;
            myIMethodCallMessage=(IMethodCallMessage)myIMessage;
            Console.WriteLine("InArgCount is  : " + 
                              myIMethodCallMessage.InArgCount.ToString());

            foreach (object myObj in myIMethodCallMessage.InArgs)
            {
               Console.WriteLine("InArgs is : " + myObj.ToString());
            }

            for(int i=0; i<myIMethodCallMessage.InArgCount; i++)
            {
               Console.WriteLine("GetArgName(" +i.ToString() +") is : " + 
                                       myIMethodCallMessage.GetArgName(i));
               Console.WriteLine("GetInArg("+i.ToString() +") is : " +
                              myIMethodCallMessage.GetInArg(i).ToString());
            }
            Console.WriteLine("");
         }
         else if (myIMessage is IMethodReturnMessage)
            Console.WriteLine("Message is of type 'IMethodReturnMessage'.");

         // Build Return Message
         myReturnMessage = new ReturnMessage(5,null,0,null,
                                       (IMethodCallMessage)myIMessage);

         Console.WriteLine("MyProxy.Invoke - Finish");
         return myReturnMessage;
      }


   }


   // The class used to obtain Metadata.
   [PermissionSet(SecurityAction.Demand, Name="FullTrust")]
   public class MyMarshalByRefClass : MarshalByRefObject
   {
      public int MyMethod(string str, double dbl, int i)
      {
         Console.WriteLine("MyMarshalByRefClass.MyMethod {0} {1} {2}", str, dbl, i);
         return 0;
      }
   }
   // Main class that drives the whole sample. 
   public class ProxySample
   {
      [SecurityPermission(SecurityAction.LinkDemand)]
      public static void Main()
      {
         Console.WriteLine("Generate a new MyProxy.");
         MyProxy myProxy = new MyProxy(typeof(MyMarshalByRefClass));

         Console.WriteLine("Obtain the transparent proxy from myProxy.");
         MyMarshalByRefClass myMarshalByRefClassObj = 
                              (MyMarshalByRefClass)myProxy.GetTransparentProxy();

         Console.WriteLine("Calling the Proxy.");
         object myReturnValue = myMarshalByRefClassObj.MyMethod("Microsoft", 1.2, 6);

         Console.WriteLine("Sample Done.");
      }
   }
}
#using <mscorlib.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Runtime::Remoting;
using namespace System::Runtime::Remoting::Proxies;
using namespace System::Runtime::Remoting::Messaging;

	// MyProxy extends the CLR Remoting RealProxy.
	// In the same class, in the Invoke method, the methods and properties of the 
	// IMethodCallMessage are demonstrated.

public __gc class MyProxy : public RealProxy 
{
public:
	MyProxy(Type* myType) : RealProxy(myType) 
	{
		// This constructor forwards the call to base RealProxy.
		// RealProxy uses the Type to generate a transparent proxy.
	}


public:
	IMessage* Invoke(IMessage* myIMessage) 
	{
		Console::WriteLine(S"MyProxy::Invoke Start");
		Console::WriteLine(S"");
		ReturnMessage* myReturnMessage = 0;

		if (dynamic_cast<IMethodCallMessage*>(myIMessage)) 
		{
			Console::WriteLine(S"Message is of type 'IMethodCallMessage*'.");
			Console::WriteLine(S"");

			IMethodCallMessage* myIMethodCallMessage;
			myIMethodCallMessage = dynamic_cast<IMethodCallMessage*>(myIMessage);
			Console::WriteLine(S"InArgCount is  : {0}", __box(myIMethodCallMessage->InArgCount));

			IEnumerator* myEnum = myIMethodCallMessage->InArgs->GetEnumerator();
			while (myEnum->MoveNext()) 
			{
				Object* myObj = __try_cast<Object*>(myEnum->Current);

				Console::WriteLine(S"InArgs is : {0}", myObj);
			}

			for (int i=0; i<myIMethodCallMessage->InArgCount; i++) 
			{
				Console::WriteLine(S"GetArgName({0}) is : {1}", __box(i), myIMethodCallMessage->GetArgName(i));
				Console::WriteLine(S"GetInArg({0}) is : {0}", __box(i), myIMethodCallMessage->GetInArg(i));
			}
			Console::WriteLine(S"");
		}
		else if (dynamic_cast<IMethodReturnMessage*>(myIMessage))
			Console::WriteLine(S"Message is of type 'IMethodReturnMessage*'.");

		// Build Return Message 
		myReturnMessage = new ReturnMessage( __box(5), 0, 0, 0, dynamic_cast<IMethodCallMessage*>(myIMessage));

		Console::WriteLine(S"MyProxy::Invoke - Finish");
		return myReturnMessage;
	}
};


// The class used to obtain Metadata.
public __gc class MyMarshalByRefClass : public MarshalByRefObject 
{
public:
	int MyMethod(String* str, double dbl, int i) 
	{
		Console::WriteLine(S"MyMarshalByRefClass::MyMethod {0} {1} {2}", str, __box(dbl), __box(i));
		return 0;
	}
};

// Main routine that drives the whole sample.
int main() 
{
	Console::WriteLine(S"Generate a new MyProxy.");
	MyProxy* myProxy = new MyProxy(__typeof(MyMarshalByRefClass));

	Console::WriteLine(S"Obtain the transparent proxy from myProxy.");
	MyMarshalByRefClass* myMarshalByRefClassObj = 
		dynamic_cast<MyMarshalByRefClass*>(myProxy->GetTransparentProxy());

	Console::WriteLine(S"Calling the Proxy.");
	Object* myReturnValue = __box(myMarshalByRefClassObj->MyMethod(S"Microsoft", 1.2, 6));

	Console::WriteLine(S"Sample Done.");
	return 0;
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

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

Community Additions

ADD
Show:
© 2015 Microsoft