Retrieves the policy instance based on the name of the service operation to be performed. The appropriate policy instance will be retrieved for the user, company, and role specified by the context object. The returned policy object will contain only the external behaviors.
Parameter |
Type |
Description |
---|---|---|
operation |
The name of the service operation to be performed. |
|
context |
Specifies information about how the method will be called. |
Value |
Type |
Description |
---|---|---|
GetPolicyByOperationResult |
The policy instance object for the operation. |
The following C# example updates a sales return document. The GetPolicyByOperation method is used to retrieve the policy instance to use for the method call.
Legacy endpoint
using System; using System.Collections.Generic; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; SalesDocumentKey salesReturnKey; SalesReturn salesReturn; Policy salesReturnPolicy; // Create an instance of the service DynamicsGP wsDynamicsGP = new DynamicsGP(); // Be sure that default credentials are 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 object context.OrganizationKey = (OrganizationKey)companyKey; // Create a Sales Return key and specify the sales return salesReturnKey = new SalesDocumentKey(); salesReturnKey.Id = "STDINV2257"; // Retrieve the sales return object salesReturn = wsDynamicsGP.GetSalesReturnByKey(salesReturnKey, context); // Set the comment property salesReturn.Comment = "Return was approved"; // Get the update policy for sales returns salesReturnPolicy = wsDynamicsGP.GetPolicyByOperation("UpdateSalesReturn", context); // Update the sales return object wsDynamicsGP.UpdateSalesReturn(salesReturn, context, salesReturnPolicy); } } }
Native endpoint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DynamicsGPWebServiceSample.DynamicsGPService; namespace DynamicsGPWebServiceSample { class Program { static void Main(string[] args) { CompanyKey companyKey; Context context; SalesDocumentKey salesReturnKey; SalesReturn salesReturn; Policy salesReturnPolicy; // 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 object context.OrganizationKey = (OrganizationKey)companyKey; // Create a Sales Return key and specify the sales return salesReturnKey = new SalesDocumentKey(); salesReturnKey.Id = "STDINV2257"; // Retrieve the sales return object salesReturn = wsDynamicsGP.GetSalesReturnByKey(salesReturnKey, context); // Set the comment property salesReturn.Comment = "Return was approved"; // Get the update policy for sales returns salesReturnPolicy = wsDynamicsGP.GetPolicyByOperation("UpdateSalesReturn", context); // Update the sales return object wsDynamicsGP.UpdateSalesReturn(salesReturn, context, salesReturnPolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }