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:
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.
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());