我有一个在生产环境中运行良好的Web服务。 但有时(随机(会引发异常:
à System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions(\r à System.Threading.Tasks.Task
1.GetResultCore(Boolean waitCompletionNotification)rn à System.Threading.Tasks.Task
1.get_Result((\r à fctSendRequestSynchrone[T](String sRequest, enumHttpMethod eMethod, Object oParams(\r à API.csRestApi.d__0'1.MoveNext((">
这是我的代码:
.........
//Here is the line which raises the 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 = SendRequest<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;
}
你有想法吗?
提前非常感谢你。
埃里克
Roman Kalinchuk, Crowcoder : 感谢您的回复。 罗曼·卡林丘克 : 这是整个堆栈跟踪:
à System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)rn à System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)rn à System.Threading.Tasks.Task`1.get_Result()rn à logs.csLogWS.fctSendRequestSynchrone[T](String sRequest, enumHttpMethod eMethod, Object oParams)rn à logs.csLogWS.sbrErrorLigneRejet(String sMessage, String sCdRejet, Exception oException)rn à logs.csLogWS.ligneLogInformation(String sMessage)rn à Importation.Program.sbrImportUnitaire(String sCdInfImp, String sFileNameIn, String sFileStructure, String sLiProcedure, String[] args)| à Service.API.csRestApi.<SendRequest>d__0`1.MoveNext()".
我在上一篇问题帖子中简化了它。 应用程序在生产环境中,我是否必须将 pdb 文件放在生产服务器上才能获得更多堆栈跟踪?
乌鸦码器:你的意思是.结果正在等待,而发送请求也在等待?你有什么建议?