Choosing the appropriate CRM account for your helper Windows Service / Console Application

One of the common practices when building medium/ large Dynamics CRM applications is to develop a helper Windows Service or Console Applications that would take the burden of complex tasks, like generating large sets of data or cleanup jobs. Any piece of functionality that would be too complex to reside inside a Plugin can be isolated into a Windows Service logic, where you have much more control and debugging / tracing power. You can expose this complex functionality through a Web Service (usually hosted inside your Windows Service) and call the Web Service method from your plugin or a Javascript resource. You can find out about the benefits and implementation details here.

First thing you will have to deal with in this scenario is how do you authenticate to CRM?  Apparently an easy question, but you should consider the following aspects:

  • Every CRM account (well, almost every) costs. Sou you cannot just go and create a dummy account for your service and use it for CRM authentication – it will simply cost you or your customer additional 30-50$ / month
  • You could use the Administrator account, but what you really want is to keep track of who exactly made what exactly changes to your data. In other words, if you use your Administrator account for everything, long term you will lose trace-ability of your data, and that could become a issue hard to ignore in certain situations. As a good practice, you should always be able to know – who and when added / updated or deleted your data., therefore, having a specialized account for your Windows Service is always a good idea.

 

The solution  is to create a non-UI free CRM account. It is free, because its only purpose is to be used in scenarios as described above – this account cannot be used by human users.
Note: I am using Dynamics CRM Online 2016.

First, create a new Dynamics (Office365) account:

Create new Dynamics CRM Acccount

Assign the appropriate roles to the newly created user (like System Administrator)

The last thing to do is to make the user Non-Interactive, which is the key thing to do, as it won’t require your company to pay for the account.

User Service - Non Interactive

Now your account is ready to be used:


<connectionStrings>
<add name="MyCRMServer" connectionString="AuthType=Office365;Username=service@****.onmicrosoft.com; Password=***;Url=https://***.crm4.dynamics.com" />
</connectionStrings>

//Use the connection string named "MyCRMServer" from the configuration file
 CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["MyCRMServer"].ConnectionString);
 var response = crmSvc.OrganizationServiceProxy.Execute(new WhoAmIRequest());

Leave a Reply

Your email address will not be published. Required fields are marked *