IOrganizationService organizationService = null;
try
{
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "......onmicrosoft.com";
clientCredentials.UserName.Password = "password";
// For Dynamics 365 Customer Engagement V9.X, set Security Protocol as TLS12
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
organizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri("">-------.api.crm8.dynamics.com/.../Organization.svc"),
null, clientCredentials, null);
if (organizationService != null)
{
// Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).OrganizationId;
Guid userid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
if (userid != Guid.Empty)
{
Console.WriteLine("Connection Successful!...");
}
}
else
{
Console.WriteLine("Failed to Established Connection!!!");
}