CRM 2013如何调试检索插件?

时间:2015-01-29 15:08:43

标签: dynamics-crm crm dynamics-crm-2013

我想调试一个检索插件,但无法使用插件注册工具,有没有其他方法来调试这种类型的插件?

1 个答案:

答案 0 :(得分:0)

您可以使用 ITracingService ,如下所示。使用跟踪服务,您可以跟踪问题的原因。

public class MyPlugin : IPlugin
{
    public void Execute(IServiceProvider serviceProvider)
    {
        IPluginExecutionContext context =
            (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

        IOrganizationServiceFactory factory;
        IOrganizationService service;

        try
        {
            tracingService.Trace("initialize context, factory and service...");
            factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            tracingService.Trace("CreateOrganizationService()");
            service = factory.CreateOrganizationService(context.UserId);

        }
        catch (Exception ex)
        {
            throw new InvalidPluginExecutionException(ex.Message, ex);
        }
    }
}