共用方式為


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 參數。

適用於