/// <summary> /// Get organization data for a specific known region only /// </summary> /// <param name="creds">User's credentials.</param> /// <param name="dataCenter">Target datacenter.</param> /// <returns></returns> public static List <OrganizationDetail> GetOrganizationsForDataCenter(string userName, string password, DataCenter dataCenter) { if (dataCenter == DataCenter.Unknown) { throw new ArgumentOutOfRangeException("DataCenter.Unknown cannot be used as a parameter for this method."); } //Get the DataCenter URL from the Description Attribute applied for the DataCenter member var type = typeof(DataCenter); var memInfo = type.GetMember(dataCenter.ToString()); var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); Uri targeturl = new Uri(((DescriptionAttribute)attributes[0]).Description); // Set up user credentials var creds = new System.ServiceModel.Description.ClientCredentials(); creds.UserName.UserName = userName; creds.UserName.Password = password; Uri appReplyUri = new Uri(redirectUrl); // Call to get organizations from global discovery var organizations = CrmServiceClient.DiscoverGlobalOrganizations( targeturl, creds, null, clientId, appReplyUri, "", false, string.Empty, PromptBehavior.Auto); return(organizations.ToList()); }