ImpersonationOption 列舉


指定服務執行個體上服務作業的模擬行為。Specifies the impersonation behavior for a service operation on a service instance.

public enum class ImpersonationOption
public enum ImpersonationOption
type ImpersonationOption = 
Public Enum ImpersonationOption


Allowed 1

如果認證可以使用,且 ImpersonateCallerForAllOperations 等於 true,則會執行模擬。Impersonation is performed if credentials are available and ImpersonateCallerForAllOperations is equal to true.

NotAllowed 0

未執行模擬。Impersonation is not performed. 如果 ImpersonateCallerForAllOperations 等於 true,則服務啟動時會發生驗證例外狀況。If ImpersonateCallerForAllOperations is equal to true, a validation exception occurs at service startup time.

Required 2

需要模擬。Impersonation is required.


下列服務程式碼範例示範如何使用 OperationBehaviorAttribute 設定模擬等級,讓某個方法模擬呼叫者。The following code example on the service shows how to have a method impersonate the caller by using the OperationBehaviorAttribute to set the impersonation level.

[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);
    return result;
<OperationBehavior(Impersonation := ImpersonationOption.Required)> _
Public Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double Implements ICalculator.Add
    Dim result = n1 + n2
    Console.WriteLine("Received Add({0},{1})", n1, n2)
    Console.WriteLine("Return: {0}", result)
    Return result
End Function


使用 ImpersonationOption 列舉來控制 Windows Communication Foundation (WCF) 應用程式中的模擬。Use the ImpersonationOption enumeration to control impersonation in Windows Communication Foundation (WCF) applications.

這個設定會與下表中 ImpersonateCallerForAllOperations 上的組態屬性互動。This setting interacts with a configuration property on ImpersonateCallerForAllOperations in the following table.