Język

RemotingServices.IsOneWay(MethodBase) Metoda

Definicja

Zwraca wartość logiczną wskazującą, czy klient, który nazwał metodę określoną w danym komunikacie, oczekuje na zakończenie przetwarzania metody przez serwer przed kontynuowaniem wykonywania.

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

Parametry

method
MethodBase

Metoda, o których mowa.

Zwraca

true jeśli metoda jest jednym ze sposobów; w przeciwnym razie, false.

Atrybuty

Wyjątki

Bezpośrednie wywołanie nie ma uprawnień do infrastruktury.

Przykłady

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

Uwagi

Po wywołaniu metody jednokierunkowej klient nie czeka na zakończenie przetwarzania komunikatu przez serwer. Metoda kliencka powraca do aplikacji bez wiedzy, czy serwer pomyślnie przetworzy komunikat. Metody są oznaczane w jeden sposób przy użyciu metody OneWayAttribute.

Metody jednokierunkowe nie mogą mieć wartości zwracanej ani żadnych parametrów wychodzących.

Dotyczy