RemotingServices.IsOneWay(MethodBase) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
回傳一個布林值,指示呼叫該訊息中指定方法的客戶端是否正在等待伺服器完成處理該方法後才繼續執行。
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標記為單向。
單向方法不能有返回值或任何出函參數。