ImpersonationOption 列舉

定義

指定服務執行個體上服務作業的模擬行為。

C#
public enum ImpersonationOption
繼承
ImpersonationOption

欄位

Allowed 1

如果認證可以使用,且 ImpersonateCallerForAllOperations 等於 true,則會執行模擬。

NotAllowed 0

未執行模擬。 如果 ImpersonateCallerForAllOperations 等於 true,則服務啟動時會發生驗證例外狀況。

Required 2

需要模擬。

範例

下列服務程式碼範例示範如何使用 OperationBehaviorAttribute 設定模擬等級,讓某個方法模擬呼叫者。

C#
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
public double Add(double n1, double n2)
{
    double result = n1 + n2;
    Console.WriteLine("Received Add({0},{1})", n1, n2);
    Console.WriteLine("Return: {0}", result);
    DisplayIdentityInformation();
    return result;
}

備註

ImpersonationOption使用 列舉來控制 Windows Communication Foundation (WCF) 應用程式中的模擬。

這個設定會與下表中 ImpersonateCallerForAllOperations 上的組態屬性互動。

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8