Export (0) Print
Expand All

CallerImpersonationScope Class

Dynamics CRM 2013

Applies To: Microsoft Dynamics CRM 2013, Microsoft Dynamics CRM Online

Identifies a user as the owner of all data changes made by calls to a Web service.

Namespace: Microsoft.Xrm.Sdk
Assembly: Microsoft.Xrm.Sdk (in Microsoft.Xrm.Sdk.dll)

'Declaration
Public NotInheritable Class CallerImpersonationScope
	Implements IDisposable

The specified user does not have to be the same user that instantiated the service. When the CallerImpersonationScope object goes out of scope and is disposed, calls to the service are owned by the original user that instantiated the service.


using (new CallerImpersonationScope(service, userId))
{
   // Display information about the logged on user.
   Guid effectiveUserId = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId;
   SystemUser systemUser = (SystemUser)service.Retrieve("systemuser", effectiveUserId, 
       new ColumnSet(new string[] {"firstname", "lastname"}));
   Console.WriteLine("Logged on user is {0} {1}.", systemUser.FirstName, systemUser.LastName);
}


System.Object
  Microsoft.Xrm.Sdk.CallerImpersonationScope

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

Windows Server 2008, Windows Server 2012, Windows 7 (All Versions), Windows 8 (All Versions)

Target Platforms

Windows Server 2008, ,Windows Server 2012, ,Windows 7 (All Versions),

Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft