I am using Microsoft Dynamics CRM 2016 SDK.
I am getting the following error messages.
The type or namespace name 'SecurityPrincipal' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'TargetOwnedAccount' could not be found (are you missing a using directive or an assembly reference?)
Here's my code.
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System;
using Microsoft.Xrm.Tooling.Connector;
using System.Configuration;
using System.Net;
using System.ServiceModel.Description;
namespace CrmSecurityRole
{
class Program
{
static void Main(string[] args)
{
Uri crmUrl = new Uri(ConfigurationManager.AppSettings["CrmServerUrl"]);
string userName = ConfigurationManager.AppSettings["UserName"];
string password = ConfigurationManager.AppSettings["Password"];
IOrganizationService service;
// Get the CRM connection string and connect to the CRM Organization
ClientCredentials credentials = new ClientCredentials();
credentials.UserName.UserName = userName;
credentials.UserName.Password = password;
credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
service = new OrganizationServiceProxy(crmUrl, null, credentials, null);
// Create the SecurityPrincipal Object
SecurityPrincipal principal = new SecurityPrincipal();
principal.Type = SecurityPrincipalType.User;
// PrincipalId is the Guid of the user to whom access is being granted
principal.PrincipalId = new Guid("7B222F98-F48A-4AED-9D09-77A19CB6EE82");
// Create the PrincipalAccess Object
PrincipalAccess principalAccess = new PrincipalAccess();
// Set the PrincipalAccess Object's Properties
principalAccess.Principal = principal;
// Gives the principal access to read
principalAccess.AccessMask = AccessRights.ReadAccess;
// Create the Target Object for the Request
TargetOwnedAccount target = new TargetOwnedAccount();
// EntityId is the Guid of the account access is being granted to
target.EntityId = new Guid("6A92D3AE-A9C9-4E44-9FA6-F3D5643753C1");
// Create the Request Object
GrantAccessRequest grant = new GrantAccessRequest();
// Set the Request Object's properties
grant.PrincipalAccess = principalAccess;
grant.Target = target;
// Execute the Request
GrantAccessResponse granted = (GrantAccessResponse)service.Execute(grant);
}
}
}
*This post is locked for comments
I have the same question (0)