//Connection au CRM public void ConnectToCRM(DisplayErr Err) { //Décla de la Config Configuration config = null; //Appel la config config = new FileConfiguration(Login, Pwd, URL, AzureID, Redirect, SecretKey); //Décla Auth, use a HttpClient object to connect to specified CRM Web service. Authentication auth = new Authentication(config); httpClient = new HttpClient(auth.ClientHandler, true); //Define the Web API base address, the max period of execute time, the // default OData version, and the default response payload format. httpClient.BaseAddress = new Uri(config.ServiceUrl + "api/data/"); httpClient.Timeout = new TimeSpan(0, 2, 0); httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0"); httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //Récup Version API Task.WaitAll(Task.Run(async() => await RunAsyncApiVersion(Err))); }
//Appel methodes Asynk pour récup la version public async Task RunAsyncApiVersion(DisplayErr Err) { try { await ReqApiVersion(GetHTTPClient()); } catch (Exception ex) { Err.DisplayException(ex); } }