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.