public async Task <GSEnvironments> GetGlobalServiceConfig(string clientName = "powerbi-msolap") { if (GlobalServiceEnvironments == null) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); try { var response = await client.PostAsync("https://api.powerbi.com/powerbi/globalservice/v201606/environments/discover?client=" + clientName, null); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var serializer = new DataContractJsonSerializer(typeof(GSEnvironments)); GlobalServiceEnvironments = serializer.ReadObject(await response.Content.ReadAsStreamAsync()) as GSEnvironments; } } catch (Exception) { // In the rare cases where we are in an environment where api.powerbi.com is inaccessible, // environments will be populated via custom discovery url. } } } return(GlobalServiceEnvironments); }
public async Task <GSEnvironments> GetGlobalServiceConfig(string endpoint = "https://api.powerbi.com", string clientName = "powerbi-msolap", bool enforceRefresh = false) { if (GlobalServiceEnvironments == null || enforceRefresh) { var defaultProtocol = ServicePointManager.SecurityProtocol; try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); var response = await client.PostAsync(endpoint + "/powerbi/globalservice/v201606/environments/discover?client=" + clientName, null); if (response.StatusCode == HttpStatusCode.OK) { var serializer = new DataContractJsonSerializer(typeof(GSEnvironments)); GlobalServiceEnvironments = serializer.ReadObject(await response.Content.ReadAsStreamAsync()) as GSEnvironments; } } } catch (Exception) { // In the rare cases where we are in an environment where api.powerbi.com is inaccessible, // environments will be populated via custom discovery url. } finally { ServicePointManager.SecurityProtocol = defaultProtocol; } } return(GlobalServiceEnvironments); }
public async Task <GSEnvironments> GetGlobalServiceConfig(string clientName = "powerbi-msolap") { if (GlobalServiceEnvironments == null) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); var response = await client.PostAsync("https://api.powerbi.com/powerbi/globalservice/v201606/environments/discover?client=" + clientName, null); var serializer = new DataContractJsonSerializer(typeof(GSEnvironments)); GlobalServiceEnvironments = serializer.ReadObject(await response.Content.ReadAsStreamAsync()) as GSEnvironments; } } return(GlobalServiceEnvironments); }