Asked by:
Cannot connect to CRM Online instance

Question
-
I created a sample app to connect to CRM online environment but I'm getting the bellow exception.
Value cannot be null. Parameter name: identityProvider
at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.AuthenticateOnlineFederationInternal(AuthenticationCredentials authenticationCredentials) at Microsoft.Xrm.Sdk.Client.ServiceConfiguration`1.Authenticate(AuthenticationCredentials authenticationCredentials) at SampleApplication.Controllers.HomeController.GetProxy[TService,TProxy](IServiceManagement`1 serviceManagement, AuthenticationCredentials authCredentials) at SampleApplication.Controllers.HomeController.Index()
The strange thing is that it is working as expected on one of the servers we have, but throws the exception I mentioned when accessed from the other. Both machines are running Windows Server 2012 with Windows Identity Foundation 3.5 installed. I'm using Microsoft.XRM.SDK v8.0.0.0 with .NET 4.5.2. Here's the code block:
{ var orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://************.crm4.dynamics.com/XRMServices/2011/Organization.svc")); var endpointType = orgServiceManagement.AuthenticationType;
var authCredentials = GetCredentials(endpointType, "*******@********.onmicrosoft.com", "**********");
var organizationProxy = GetProxy<IOrganizationService, OrganizationServiceProxy>(orgServiceManagement, authCredentials);
organizationProxy.EnableProxyTypes(); organizationProxy.Authenticate(); } //rest of the code...
And here's the essential part of the two used methods:
private static AuthenticationCredentials GetCredentials(AuthenticationProviderType endpointType, string username, string pass) { var authCredentials = new AuthenticationCredentials(); authCredentials.ClientCredentials.UserName.UserName = username; authCredentials.ClientCredentials.UserName.Password = pass; authCredentials.SupportingCredentials = new AuthenticationCredentials(); authCredentials.SupportingCredentials.ClientCredentials = Microsoft.Crm.Services.Utility.DeviceIdManager.LoadOrRegisterDevice(); return authCredentials; } private static TProxy GetProxy<TService, TProxy>(IServiceManagement<TService> serviceManagement, AuthenticationCredentials authCredentials) where TService : class where TProxy : ServiceProxy<TService> { Type classType = typeof(TProxy); if (serviceManagement.AuthenticationType != AuthenticationProviderType.ActiveDirectory) { var tokenCredentials = serviceManagement.Authenticate(authCredentials); return (TProxy)classType .GetConstructor(new Type[] { typeof(IServiceManagement<TService>), typeof(SecurityTokenResponse) }) .Invoke(new object[] { serviceManagement, tokenCredentials.SecurityTokenResponse }); } //other staff here }
I would appreciate any help! Thanks!
Update: I have tried one of the sample apps which ships with the SDK on the problematic server and got the below error:
Unable to connect to the remote serverA connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 131.253.61.96:443
Then we have white listed all the IP Ranges listed here: https://support.microsoft.com/en-us/kb/2728473 plus the login.live.com IPs I was able to find,
but this doesn't helped.
- Edited by Yordan Terz Wednesday, December 21, 2016 2:33 PM
Tuesday, December 20, 2016 4:02 PM
All replies
-
Hello Yordan,
I would suggest you to redesign your apps to use easier approach connecting to CRM - http://butenko.pro/2016/12/migrating-apps-microsoft-xrm-client-microsoft-xrm-tooling/
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesTuesday, December 20, 2016 4:09 PMModerator -
Hello Yordan,
I would suggest you to redesign your apps to use easier approach connecting to CRM
Hi Andrii,
Thanks for your response. I followed the steps in your blog and migrated my sample app to the easier approach but I got similar result or at least similar behavior. This time I get the below exception when trying to execute simple WhoAmIRequest:
Object reference not set to an instance of an object. at Microsoft.Xrm.Tooling.Connector.CrmServiceClient.Execute(OrganizationRequest request)
This happens on only one of the two servers we have. It works fine on the other. Please share your thoughts?
Wednesday, December 21, 2016 11:19 AM -
Unfortunately I have no other ideas. Provided code works for any org I can reach.
Dynamics CRM MVP
Read My blog
Subscribe for one of my coursesWednesday, December 21, 2016 11:46 AMModerator -
Unfortunately I have no other ideas. Provided code works for any org I can reach.
Ok, thank you anyway!
Wednesday, December 21, 2016 11:54 AM -
Hey,
Try using .Net framework 4.6.2
Jugal Kishore Dandamudi.
Wednesday, December 21, 2016 12:03 PM