Hello Experts,
I am trying to create a console application in .NET which communicates with CRM so would perform CRUD operation but I am not able to connect getting error always. I am sharing the code snippet.using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
using System;
namespace ConsoleAppWithD365
{
class Program
{
static void Main(string[] args)
{
CrmServiceClient crmSvc = getOrganizationService();
Console.ReadLine();
}
public static CrmServiceClient getOrganizationService()
{
CrmServiceClient crmSvc = null;
String connectionString = "AuthType=OAuth;Username=xxxx@xxxx.onmicrosoft.com; Password=xxxx;Url=https://xxx.crm.dynamics.com;AppId=xxxx; RedirectUri=http://localhost;LoginPrompt=Auto";
try
{;
crmSvc = new CrmServiceClient(connectionString);
if (crmSvc != null)
{
var whoAmIResponse = ((WhoAmIResponse)crmSvc.Execute(new WhoAmIRequest()));
if (whoAmIResponse != null)
{
Console.WriteLine("Connection OK....");
Console.WriteLine(whoAmIResponse.UserId);
}
else
{
Console.WriteLine("Not Connected....");
}
}
}
catch (Exception e)
{
Console.WriteLine("ERROR...");
Console.WriteLine(e.Message);
}
return crmSvc;
}
}
}
I have added Dynamics 365 SDK references to the project via NuGet.
While using above code getting below error.
I have registered the Application to the azure, Generated the Client secret also created the application user with the current application id by following steps given here : https://blog.magnetismsolutions.com/blog/paulnieuwelaar/2021/9/21/setting-up-an-application-user-in-dynamics-365
Still getting error.
I can not use the Auth type Office 365 as it is depreciated. Please help to generate the OrgService to perform the CRUD operation in dynamics 365 using console app.