OrganizationService在RetrieveMultiple请求期间抛出身份验证异常

时间:2015-10-30 15:14:44

标签: c# dynamics-crm-2011 dynamics-crm

我已经为CRM在线2015发布了一个Post | sync | sandbox |更新消息CRM插件,除了RetrieveMultiple调用之外一切正常

我创建了IOrganizationService

    public static IOrganizationService GetOrganizationServiceByCurrentUser(this IServiceProvider serviceProvider)
    {
        var serviceFactory = serviceProvider.GetService<IOrganizationServiceFactory>();
        var context = serviceProvider.GetService<IPluginExecutionContext>();
        return serviceFactory.CreateOrganizationService(context.UserId);
    }

致电RetrieveMultiple

        Entity config = organizationService.RetrieveMultiple(new FetchExpression(CrmConstants.Query.AzureCofig))
                                           .Entities.FirstOrDefault();

出现以下错误

  

未在配置的身份验证端点上找到用户名   安全令牌服务!

我尝试过同样的单元测试,CrmConnection一切正常。看起来插件执行权有问题。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

如果检索任何配置部分,则必须在系统帐户下创建IOrganizationService,而不是用户上下文

   public static IOrganizationService GetOrganizationServiceByCurrentUser(this IServiceProvider serviceProvider)
    {
        var serviceFactory = serviceProvider.GetService<IOrganizationServiceFactory>();
        return serviceFactory.CreateOrganizationService(null);
    }