This project is read-only.

How to Impersonate Declaratively In WCF

- J.D. Meier, Carlos Farre, Jason Taylor, Prashant Bansode, Steve Gregersen, Madhu Sundararajan, Rob Boucher

Use the OperationBehavior attribute to impersonate declaratively. There are two options for declarative impersonation:
  • Impersonating on specific operations
  • Impersonating on the entire service
Impersonating on specific operations
Use this option when you want to impersonate the original caller for the entire duration of specific operation. You can impersonate declaratively by applying the OperationBehaviorAttribute attribute on any operation that requires client impersonation, as shown in the following code example.
[*OperationBehavior*(Impersonation = ImpersonationOption.*Required*)]
public string GetData(int value)
{
   return “test”;
}

Impersonating on the entire service
Use this option when you want to impersonate the original caller for entire duration of all the operations. For impersonating the entire service set the impersonateCallerForAllOperations attribute to "true" in the WCF configuration file, as shown in the following example.
…
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <serviceAuthorization *impersonateCallerForAllOperations="true"* />
    </behavior>
  </serviceBehaviors>
</behaviors>
…

When impersonating for all operations, the Impersonation property of the OperationBehaviorAttribute applied to each method must also be set to either Allowed or Required.

Additional Resources

Last edited Jun 13, 2008 at 8:31 PM by prashantbansode, version 1

Comments

No comments yet.