Bonjour à tous,

J'ai un Service Web qui marche bien sur un environnement de production.
Mais de temps en temps j'ai une exception qui est levée :
à System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n
à System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)\r\n
à System.Threading.Tasks.Task`1.get_Result()\r\n
à fctSendRequestSynchrone[T](String sRequest, enumHttpMethod eMethod, Object oParams)\r\n
à API.csRestApi.<SendRequest>d__0`1.MoveNext()"
Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
.........
 
//Voici la ligne qui génère l'exception :
fctSendRequestSynchrone<string>(string.Format("logs/{0}/message", _lIdLog), cs.enumHttpMethod.POST, oLogLigne);
 
.........
//-------------------------------------------------------------------------------------
 
private T fctSendRequestSynchrone<T>(string sRequest, csRestApi.enumHttpMethod eMethod, object oParams = null)
        {
            Task<T> otask = fctSendRequest<T>(sRequest, eMethod, oParams);
            return otask.Result;
        }
 
//-------------------------------------------------------------------------------------
 
public async Task<T> SendRequest<T>(string sAction, enumHttpMethod eMethod, object oParams = null)
        {
 
            string sResponse = string.Empty;
            T oValue;
 
                  using (var oClient = new HttpClient(new LogginHandler(_oCnx, new HttpClientHandler())))
                {
                    oClient.DefaultRequestHeaders.Accept.Clear();
                    oClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
 
                    string sRequest = string.Concat(_sUrlApi, "/", sAction);
 
                    if (_oToken != null)
                    {
                        oClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(_oToken["token_type"], _oToken["access_token"]);
                    }                  
 
                    using (HttpResponseMessage oResponse = await oClient.PostAsJsonAsync(sRequest, oParams))
                    {
                          if (oResponse.IsSuccessStatusCode)
                          {
                                HttpContent content = oResponse.Content;
                                sResponse = await content.ReadAsStringAsync();
                          }
                          else
                          {
                               throw new RestApiException(oResponse);
                          }
                    }
 
                }
 
                oValue = JsonConvert.DeserializeObject<T>(sResponse);
 
            return oValue;
        }
Auriez vous une idée du problème ?

Merci beaucoup par avance.

Eric