1

I've a Post|sync|sandbox|Update Message CRM plugin for CRM online 2015, all works fine except RetrieveMultiple call

I've created IOrganizationService

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

after call RetrieveMultiple

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

following error is appeared

The authentication endpoint Username was not found on the configured Secure Token Service!

I've tried to do the same thru unit test and CrmConnection all works fine. Looks like something wrong with plugin execution rights. Any idea?

GSerjo
  • 4,725
  • 1
  • 36
  • 55
  • looks like an issue with the ADFS configuration: http://help.clickdimensions.com/the-authentication-endpoint-username-was-not-found-on-the-configured-secure-token-service-error-when-registering/ including information on your deployment/environment would help diagnose the issue. – Joseph Duty Oct 30 '15 at 15:46
  • 1
    What happens if you do a "organizationService.Retrieve("systemuser", context.InitiatingUserId, new ColumnSet(true))"; That should return the current user info, if that works, there's something odd about you retrievemultiple and I Think it looks sort of funny, but that might be that surrounding code is missing :) – Rickard N Nov 02 '15 at 14:11
  • I've fixed the issue, it was a bug :) The entity is a custom config section so I had to call `RetrieveMultiple` under the system account – GSerjo Nov 02 '15 at 15:57

1 Answers1

2

If you retrieve any config sections you have to create IOrganizationService under the system account, not the user context

   public static IOrganizationService GetOrganizationServiceByCurrentUser(this IServiceProvider serviceProvider)
    {
        var serviceFactory = serviceProvider.GetService<IOrganizationServiceFactory>();
        return serviceFactory.CreateOrganizationService(null);
    }
GSerjo
  • 4,725
  • 1
  • 36
  • 55