Hi,
I am new to Dynamics Environment. I am trying to connect to my Trial Instance of Dynamics 365 from .net Console Application.
I can login with my Username and Password from browser. But I can't login from application.
private static string GetCrmService(string name) { IOrganizationService OrganizationService = null; try { ClientCredentials mycredentials = new ClientCredentials(); mycredentials.UserName.UserName = "My UserName"; mycredentials.UserName.Password = "My Password"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; OrganizationService = (IOrganizationService)new OrganizationServiceProxy(new Uri("My Organisation Service Api"), null, mycredentials, null); if (OrganizationService != null) { Guid userId = ((WhoAmIResponse)OrganizationService.Execute(new WhoAmIRequest())).UserId; if (userId.Equals(Guid.Empty)) { Console.WriteLine("Connection can't be established"); return userId.ToString(); } return ""; } else { Console.WriteLine("Connection Established Successfully"); return ""; } } catch(Exception ex) { Console.WriteLine("Exception caught:" + ex.Message); Console.WriteLine("Inner Exception:" + ex.InnerException+"\nMesssage:"+ex.InnerException.Message); return ""; } }
It shows Authentication Error. But I am using same Username and Password for Browser login. That is fine.
Can someone help me out