Announcements
Hi.
I've been using the CrmServiceClient with Tls12 in C# for a while now but last night it stopped working.
The LastCRMError is "Unable to Login to Dynamics CRM"
I haven't made any changes to this and testing the connection with XrmToolBox succeeds.
Any ideas
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
CrmServiceClient service = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString);
Hi,
Try below code and you should be able to connect to CRM from console/c#
// e.g. yourorg.crm.dynamics.com
string url = "";
// e.g. you@yourorg.onmicrosoft.com
string userName = "";
// e.g. y0urp455w0rd
string password = "";
string conn = $@"Url = {url};AuthType = OAuth;UserName = {userName};Password = {password};
AppId = 51f81489-12ee-4a9e-aaae-a2591f45987d;
RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97;
LoginPrompt=Never;RequireNewInstance = True";
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
var svc = new CrmServiceClient(conn);
AppId and RedirectUri is provided by microsoft and it will work for all crm online instance.
Please mark my answer verified if i were helpful
ok so lets take the bazooka :-)
here is some code to connect with clientid/clientsecret
We are using this for some month now without any problems.
https://stackoverflow.com/questions/36160766/how-do-i-connect-a-server-service-to-dynamics-online
this is the class
public class DynamicsCeClientIdClient { public string TenantId = ""; // from your app registration overview "Directory (tenant) ID" public string ClientId = ""; // from your app registration overview "Application (client) ID" public string ClientSecret = ""; // secret generated in step 1 public string LoginUrl = "https://login.microsoftonline.com"; // aad login url public string OrganizationName = ""; // check your dynamics login url, e.g. https://..dynamics.com public string OrganizationRegion = "crm4"; // might be crm for north america, check your dynamics login url public DynamicsCeClientIdClient(string organizationName, string clientId, string clientSecret, string tenantId, string region = "crm4") { TenantId = tenantId; ClientId = clientId; ClientSecret = clientSecret; OrganizationName = organizationName; OrganizationRegion = region; } private string GetServiceUrl() { return $"{GetResourceUrl()}/XRMServices/2011/Organization.svc/web"; } private string GetResourceUrl() { return $"https://{OrganizationName}.api.{OrganizationRegion}.dynamics.com"; } private string GetAuthorityUrl() { return $"{LoginUrl}/{TenantId}"; } public async Task CreateClient(string sdkVersion = "9.1") { var context = new AuthenticationContext(GetAuthorityUrl(), false); context.ExtendedLifeTimeEnabled = true; var token = await context.AcquireTokenAsync(GetResourceUrl(), new ClientCredential(ClientId, ClientSecret)); return new OrganizationWebProxyClient(new Uri(GetServiceUrl()), true) { HeaderToken = token.AccessToken, SdkClientVersion = "9.1" }; } public async Task CreateContext() { var client = await CreateClient(); return new OrganizationServiceContext(client); } public async Task TestApiCall() { var context = await CreateContext(); // send a test request to verify authentication is working var response = (WhoAmIResponse)context.Execute(new WhoAmIRequest()); } }
and this is how you create the client:
var organization = "myorg"; var clientId = "myclientid"; var clientSecret = "myclientsecret"; var tenantId = "mytenantid"; var region = "crm4"; var client = new DynamicsCeClientIdClient(organization, clientId, clientSecret, tenantId, region); var c = client.CreateClient("9.1").Result;
Are you able to use my console code to connect to your instance(s) of dynamics?
I dont have fiddler
Hi. I've had a look at this but it seems a lot of work to resolve what is apparently an easy fix. At least until 2022
and make sure fiddler is not running :-P this can also cause connection issues.
I've send you an message.
Hi Stuie,
check the following link
https://exptechsolutions.blogspot.com/2018/02/d365-crm-v9-troubleshooting-tls12-ssrs.html
hope help you
tried that too :(
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156