Dela via


Removing policies and behaviors

To allow your service to be uninstalled, add methods that remove your policy metadata from the Dynamics GP Service metadata. When you remove policy metadata for a service, you must first remove the policies and then remove the behaviors.

  1. Add methods that create keys.

    Implement a method that takes a GUID and returns a policy key. Use the static GetInstance method of the PolicyKey class to create a key. Use the GUID parameter to populate the ID property of the key.

    private PolicyKey CreatePolicyKey(Guid guid)
    

{ PolicyKey policyKey = PolicyKey.GetInstance(); policyKey.Id = guid;

return policyKey;

}

Implement a method that takes a GUID and returns a behavior key. Use the static GetInstance method of the BehaviorKey class to create a key. Use the GUID parameter to populate the ID property of the key.

<pre class="checklistscript" IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml">private BehaviorKey CreateBehaviorKey(Guid guid)

{ BehaviorKey behaviorKey = BehaviorKey.GetInstance(); behaviorKey.Id = guid;

return behaviorKey;

}

  1. Add a method to remove policies.

    In the method, use the ServiceFactory to instantiate a PolicyDataService object. Then, use the DeletePolicy method of the PolicyDataService to remove policy metadata.

    The following code example removes the policy metadata for the sample Leads service operations. Notice how the key values that were defined during initialization are used to specify the policies.

    private void RemovePolicies()
    

{ PolicyDataService policyDataService = (PolicyDataService)ServiceFactory.GetServiceInstance( CommonConstants.PolicyDataService);

policyDataService.DeletePolicy(context,
    CreatePolicyKey(deleteLeadPolicyId));
policyDataService.DeletePolicy(context,
    CreatePolicyKey(createLeadPolicyId));
policyDataService.DeletePolicy(context,
    CreatePolicyKey(updateLeadPolicyId));

}

  1. Add a method to remove behaviors.

    In the method, use the ServiceFactory to instantiate a PolicyDataService object. Use the DeleteBehavior method of the PolicyDataService to remove behavior metadata.

    The following code example removes the behavior metadata for the sample Leads service. Notice how the key values that were defined during initialization are used to specify the behavior.

    private void RemoveBehaviors()
    

{ PolicyDataService policyDataService = (PolicyDataService)ServiceFactory.GetServiceInstance( CommonConstants.PolicyDataService);

policyDataService.DeleteBehavior(context,
CreateBehaviorKey(createQualifiedLeadBehaviorId));

}