Retrieves the list of roles that have policy instances for the specified policy. The roles are returned as role keys (GUID values) that correspond to roles defined in the Dynamics Security Service.
Parameter |
Type |
Description |
---|---|---|
policyKey |
The policy key object that specifies which policy will have roles returned. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetPolicyRolesResult |
The list of role keys (GUID values) for which policy instances exist. The values correspond to roles defined in the Dynamics Security Service. |
The following C# example retrieves the policy roles that are available for the Create Customer policy in the sample company Fabrikam. The Create Customer policy is identified using the GUID value from the Policy Reference. The Context object specifies that the sample company is to be examined. A series of message boxes display the total number of roles, and the ID of each role.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; RoleKey[] roleKeyList; PolicyKey policyKey; // Create an instance of the service DynamicsGP wsDynamicsGP = new DynamicsGP(); // Be sure that default credentials are being used wsDynamicsGP.UseDefaultCredentials = true; // Create a context with which to call the service context = new Context(); // Specify which company to use (sample company) companyKey = new CompanyKey(); companyKey.Id = (-1); // Set up the context context.OrganizationKey = (OrganizationKey)companyKey; // Create the policy key for the Create Customer policy policyKey = new PolicyKey(); policyKey.Id = new Guid("94880780-186c-43c8-b484-efcdd03cbdbe"); // Retrieve the list of roles for this policy in the current company roleKeyList = wsDynamicsGP.GetPolicyRoles(policyKey, context); // Display the number of roles MessageBox.Show("Total roles for this policy: " + roleKeyList.Length.ToString()); foreach (RoleKey r in roleKeyList) { MessageBox.Show(r.Id.ToString()); } } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; RoleKey[] roleKeyList; PolicyKey policyKey; // Create an instance of the service DynamicsGPClient wsDynamicsGP = new DynamicsGPClient(); // Create a context with which to call the service context = new Context(); // Specify which company to use (sample company) companyKey = new CompanyKey(); companyKey.Id = (-1); // Set up the context context.OrganizationKey = (OrganizationKey)companyKey; // Create the policy key for the Create Customer policy policyKey = new PolicyKey(); policyKey.Id = new Guid("94880780-186c-43c8-b484-efcdd03cbdbe"); // Retrieve the list of roles for this policy in the current company roleKeyList = wsDynamicsGP.GetPolicyRoles(policyKey, context); // Display the number of roles MessageBox.Show("Total roles for this policy: " + roleKeyList.Length.ToString()); foreach (RoleKey r in roleKeyList) { MessageBox.Show(r.Id.ToString()); } // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }