One of the ways to connect through code to Dynamics 365 is to use CrmServiceClient, which allows us to connect using a connection string. CrmServiceClient is located in Microsoft.Xrm.Tooling.Connector.
Moving forward create a new Visual Studio project and add Microsoft.CrmSdk.XrmTooling.CoreAssembly nuget package
Include below namespaces in class to use package.
using Microsoft.Xrm.Tooling.Connector;
using Microsoft.Xrm.Sdk;
Add a connection string to your project in below format
<connectionStrings>
<add name="Dev" connectionString="AuthType=Office365; Username=admin@sampleorg.onmicrosoft.com; Password=yourpassword; Url=https://sampleorg.crm.dynamics.com/; RequireNewInstance=true LoginPrompt=Never"/>
</connectionStrings>
You can read more about connection string here: Use connection strings in XRM tooling to connect to Dynamics 365
Use the below code to create get IOrganizationService
Testing connection..
Hope this helps you..!
0 Comments