RemotingServices.IsOneWay(MethodBase) 方法

定义

返回一个布尔值,该值指示调用给定消息中指定的方法的客户端在继续执行之前是否等待服务器完成该方法的处理。

public:
 static bool IsOneWay(System::Reflection::MethodBase ^ method);
public static bool IsOneWay (System.Reflection.MethodBase method);
[System.Security.SecurityCritical]
public static bool IsOneWay (System.Reflection.MethodBase method);
static member IsOneWay : System.Reflection.MethodBase -> bool
[<System.Security.SecurityCritical>]
static member IsOneWay : System.Reflection.MethodBase -> bool
Public Shared Function IsOneWay (method As MethodBase) As Boolean

参数

method
MethodBase

上述方法。

返回

如果该方法是单向的,则为 true;否则为 false

属性

例外

直接调用方没有基础结构权限。

示例

public ref class HelloServer: public MarshalByRefObject
{
public:
   HelloServer()
   {
      Console::WriteLine( "HelloServer activated." );
   }

   [OneWay]
   void SayHelloToServer( String^ name )
   {
      Console::WriteLine( "Client invoked SayHelloToServer(\" {0}\").", name );
   }

   // IsOneWay: Note the lack of the OneWayAttribute adornment on this method.
   [SecurityPermissionAttribute(SecurityAction::Demand, Flags=SecurityPermissionFlag::Infrastructure)]   
   String^ SayHelloToServerAndWait( String^ name )
   {
      Console::WriteLine( "Client invoked SayHelloToServerAndWait(\" {0}\").", name );
      Console::WriteLine( "Client waiting for return? {0}", RemotingServices::IsOneWay( MethodBase::GetCurrentMethod() ) ? (String^)"No" : "Yes" );
      return String::Format( "Hi there, {0}.", name );
   }
};
public class HelloServer : MarshalByRefObject {

   public HelloServer() {
      Console.WriteLine("HelloServer activated.");
   }

   [OneWay()]
   public void SayHelloToServer(string name) {
      Console.WriteLine("Client invoked SayHelloToServer(\"{0}\").", name);
   }   

   // IsOneWay
   // Note the lack of the OneWayAttribute adornment on this method.
   public string SayHelloToServerAndWait(string name) {
      Console.WriteLine("Client invoked SayHelloToServerAndWait(\"{0}\").", name);

      Console.WriteLine(
         "Client waiting for return? {0}",
         RemotingServices.IsOneWay(MethodBase.GetCurrentMethod()) ? "No" : "Yes"
      );

      return "Hi there, " + name + ".";
   }
}
Public Class HelloServer
    Inherits MarshalByRefObject

    Shared Sub New()
        Console.WriteLine("HelloServer activated.")
    End Sub

    <OneWay()> Public Sub SayHelloToServer(ByVal name As String)
        Console.WriteLine("Client invoked SayHelloToServer(""{0}"").", name)
    End Sub

    'IsOneWay
    ' Note the lack of the OneWayAttribute adornment on this method.
<SecurityPermission(SecurityAction.Demand)> _
    Public Function SayHelloToServerAndWait(ByVal name As String) As String
        Console.WriteLine("Client invoked SayHelloToServerAndWait(""{0}"").", name)

        Console.WriteLine( _
            "Client waiting for return? {0}", _
            IIf(RemotingServices.IsOneWay(MethodBase.GetCurrentMethod()), "No", "Yes") _
        )

        Return "Hi there, " + name + "."
    End Function

End Class

注解

调用单向方法时,客户端不会等待服务器完成消息处理。 客户端方法返回到应用程序,但不知道服务器是否会成功处理消息。 使用 OneWayAttribute将方法标记为单向。

单向方法不能具有返回值或任何 out 参数。

适用于