CallerImpersonationScope Class
Applies To: Dynamics CRM 2015
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)
Inheritance Hierarchy
System.Object
Microsoft.Xrm.Sdk.CallerImpersonationScope
Syntax
public sealed class CallerImpersonationScope : IDisposable
public ref class CallerImpersonationScope sealed : IDisposable
[<Sealed>]
type CallerImpersonationScope =
class
interface IDisposable
end
Public NotInheritable Class CallerImpersonationScope
Implements IDisposable
Constructors
Name | Description | |
---|---|---|
CallerImpersonationScope(IOrganizationService, Guid) | Initializes a new instance of theCallerImpersonationScope class. |
Methods
Name | Description | |
---|---|---|
Dispose() | Disposes the CallerImpersonationScope object. |
|
Equals(Object) | (Inherited from Object.) |
|
GetHashCode() | (Inherited from Object.) |
|
GetType() | (Inherited from Object.) |
|
ToString() | (Inherited from Object.) |
Remarks
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);
}
Thread Safety
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Microsoft.Xrm.Sdk Namespace
Impersonate another user
Return to top
© 2016 Microsoft. All rights reserved. Copyright