IMethodReturnMessage 接口
定义方法调用返回消息接口。
**命名空间:**System.Runtime.Remoting.Messaging
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
<ComVisibleAttribute(True)> _
Public Interface IMethodReturnMessage
Inherits IMethodMessage, IMessage
用法
Dim instance As IMethodReturnMessage
[ComVisibleAttribute(true)]
public interface IMethodReturnMessage : IMethodMessage, IMessage
[ComVisibleAttribute(true)]
public interface class IMethodReturnMessage : IMethodMessage, IMessage
/** @attribute ComVisibleAttribute(true) */
public interface IMethodReturnMessage extends IMethodMessage, IMessage
ComVisibleAttribute(true)
public interface IMethodReturnMessage extends IMethodMessage, IMessage
备注
方法调用返回消息表示对消息接收器尾部的对象上的方法调用的响应。IMethodReturnMessage 是作为在远程对象上调用的方法的结果而生成的,并且用于将该方法调用的结果返回到调用方。
示例
下面的代码示例显示了一个重写 RealProxy.Invoke 的自定义代理,目的是将返回消息写入到控制台。
<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Public Class MyProxy
Inherits RealProxy
Private stringUri As String
Private myMarshalByRefObject As MarshalByRefObject
Public Sub New(myType As Type)
MyBase.New(myType)
myMarshalByRefObject = CType(Activator.CreateInstance(myType), MarshalByRefObject)
Dim myObject As ObjRef = RemotingServices.Marshal(myMarshalByRefObject)
stringUri = myObject.URI
End Sub 'New
Public Overrides Function Invoke(myMessage As IMessage) As IMessage
Dim myCallMessage As IMethodCallMessage = CType(myMessage, IMethodCallMessage)
Dim myIMethodReturnMessage As IMethodReturnMessage = RemotingServices. _
ExecuteMessage(myMarshalByRefObject, myCallMessage)
Console.WriteLine("Method name : " + myIMethodReturnMessage.MethodName)
Console.WriteLine("The return value is : " + myIMethodReturnMessage.ReturnValue)
' Get number of 'ref' and 'out' parameters.
Dim myArgOutCount As Integer = myIMethodReturnMessage.OutArgCount
Console.WriteLine("The number of 'ref', 'out' parameters are : " + _
myIMethodReturnMessage.OutArgCount.ToString())
' Gets name and values of 'ref' and 'out' parameters.
Dim i As Integer
For i = 0 To myArgOutCount - 1
Console.WriteLine("Name of argument {0} is '{1}'.", i, _
myIMethodReturnMessage.GetOutArgName(i))
Console.WriteLine("Value of argument {0} is '{1}'.", i, _
myIMethodReturnMessage.GetOutArg(i))
Next i
Console.WriteLine()
Dim myObjectArray As Object() = myIMethodReturnMessage.OutArgs
For i = 0 To myObjectArray.Length - 1
Console.WriteLine("Value of argument {0} is '{1}' in OutArgs", i, myObjectArray(i))
Next i
Return myIMethodReturnMessage
End Function 'Invoke
End Class 'MyProxy
[PermissionSet(SecurityAction.Demand, Name="FullTrust")]
public class MyProxy : RealProxy
{
String stringUri;
MarshalByRefObject myMarshalByRefObject;
public MyProxy(Type myType): base(myType)
{
myMarshalByRefObject = (MarshalByRefObject)Activator.CreateInstance(myType);
ObjRef myObject = RemotingServices.Marshal(myMarshalByRefObject);
stringUri = myObject.URI;
}
public override IMessage Invoke(IMessage myMessage)
{
IMethodCallMessage myCallMessage = (IMethodCallMessage)myMessage;
IMethodReturnMessage myIMethodReturnMessage =
RemotingServices.ExecuteMessage(myMarshalByRefObject, myCallMessage);
Console.WriteLine("Method name : " + myIMethodReturnMessage.MethodName);
Console.WriteLine("The return value is : " + myIMethodReturnMessage.ReturnValue);
// Get number of 'ref' and 'out' parameters.
int myArgOutCount = myIMethodReturnMessage.OutArgCount;
Console.WriteLine("The number of 'ref', 'out' parameters are : " +
myIMethodReturnMessage.OutArgCount);
// Gets name and values of 'ref' and 'out' parameters.
for(int i = 0; i < myArgOutCount; i++)
{
Console.WriteLine("Name of argument {0} is '{1}'.",
i, myIMethodReturnMessage.GetOutArgName(i));
Console.WriteLine("Value of argument {0} is '{1}'.",
i, myIMethodReturnMessage.GetOutArg(i));
}
Console.WriteLine();
object[] myObjectArray = myIMethodReturnMessage.OutArgs;
for(int i = 0; i < myObjectArray.Length; i++)
Console.WriteLine("Value of argument {0} is '{1}' in OutArgs",
i, myObjectArray[i]);
return myIMethodReturnMessage;
}
}
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::LinkDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
[System::Security::Permissions::SecurityPermissionAttribute
(System::Security::Permissions::SecurityAction::InheritanceDemand,
Flags=System::Security::Permissions::SecurityPermissionFlag::Infrastructure)]
public ref class MyProxy: public RealProxy
{
private:
String^ stringUri;
MarshalByRefObject^ myMarshalByRefObject;
public:
MyProxy( Type^ myType ) : RealProxy( myType )
{
myMarshalByRefObject = dynamic_cast<MarshalByRefObject^>(Activator::CreateInstance( myType ));
ObjRef^ myObject = RemotingServices::Marshal( myMarshalByRefObject );
stringUri = myObject->URI;
}
virtual IMessage^ Invoke( IMessage^ myMessage ) override
{
IMethodCallMessage^ myCallMessage = (IMethodCallMessage^)( myMessage );
IMethodReturnMessage^ myIMethodReturnMessage =
RemotingServices::ExecuteMessage( myMarshalByRefObject, myCallMessage );
Console::WriteLine( "Method name : {0}", myIMethodReturnMessage->MethodName );
Console::WriteLine( "The return value is : {0}", myIMethodReturnMessage->ReturnValue );
// Get number of 'ref' and 'out' parameters.
int myArgOutCount = myIMethodReturnMessage->OutArgCount;
Console::WriteLine( "The number of 'ref', 'out' parameters are : {0}",
myIMethodReturnMessage->OutArgCount );
// Gets name and values of 'ref' and 'out' parameters.
for ( int i = 0; i < myArgOutCount; i++ )
{
Console::WriteLine( "Name of argument {0} is '{1}'.",
i, myIMethodReturnMessage->GetOutArgName( i ) );
Console::WriteLine( "Value of argument {0} is '{1}'.",
i, myIMethodReturnMessage->GetOutArg( i ) );
}
Console::WriteLine();
array<Object^>^myObjectArray = myIMethodReturnMessage->OutArgs;
for ( int i = 0; i < myObjectArray->Length; i++ )
Console::WriteLine( "Value of argument {0} is '{1}' in OutArgs",
i, myObjectArray[ i ] );
return myIMethodReturnMessage;
}
};
/** @attribute SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)
*/
public class MyProxy extends RealProxy
{
private String stringUri;
private MarshalByRefObject myMarshalByRefObject;
public MyProxy(Type myType)
{
super(myType);
myMarshalByRefObject
= (MarshalByRefObject)Activator.CreateInstance(myType);
ObjRef myObject = RemotingServices.Marshal(myMarshalByRefObject);
stringUri = myObject.get_URI();
} //MyProxy
public IMessage Invoke(IMessage myMessage)
{
IMethodCallMessage myCallMessage = (IMethodCallMessage)myMessage;
IMethodReturnMessage myIMethodReturnMessage
= RemotingServices.ExecuteMessage(myMarshalByRefObject,
myCallMessage);
Console.WriteLine("Method name : "
+ myIMethodReturnMessage.get_MethodName());
Console.WriteLine("The return value is : "
+ myIMethodReturnMessage.get_ReturnValue());
// Get number of 'ref' and 'out' parameters.
int myArgOutCount = myIMethodReturnMessage.get_OutArgCount();
Console.WriteLine("The number of 'ref', 'out' parameters are : "
+ myIMethodReturnMessage.get_OutArgCount());
// Gets name and values of 'ref' and 'out' parameters.
for (int i = 0; i < myArgOutCount; i++) {
Console.WriteLine("Name of argument {0} is '{1}'.",
System.Convert.ToString(i),
myIMethodReturnMessage.GetOutArgName(i));
Console.WriteLine("Value of argument {0} is '{1}'.",
System.Convert.ToString(i),
myIMethodReturnMessage.GetOutArg(i));
}
Console.WriteLine();
Object myObjectArray[] = myIMethodReturnMessage.get_OutArgs();
for (int i = 0; i < myObjectArray.length; i++) {
Console.WriteLine("Value of argument {0} is '{1}' in OutArgs",
System.Convert.ToString(i), myObjectArray.get_Item(i));
}
return myIMethodReturnMessage;
} //Invoke
} //MyProxy
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
IMethodReturnMessage 成员
System.Runtime.Remoting.Messaging 命名空间