.NET EF HttpRequestException使用等待

时间:2017-08-15 13:58:53

标签: c# .net entity-framework model-view-controller visual-studio-2015

我有以下代码在最后一行抛出异常。我正在使用Visual Studio 2015,EF .NET MVC。该方法是async Task<ActionResult>,不使用“使用”块。

我一直在喋喋不休地寻求答案,是否有人有解决方案?

var data = new Dictionary<string, object>
{
    {"accountId", directDebit.Account.Id},
    {"ddInfoId", directDebit.Id},
    {"instructionType", type}
};

HttpClient.DefaultRequestHeaders.Clear();
var uri = new Uri(_apiBaseUrl + "/Correspondence/GenerateDirectDebitCorrespondence");
var authToken = await _apiCommunicator.GetToken();
HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authToken);

var response = await HttpClient.PostAsJsonAsync(uri, data);

更新:更多信息,API调用是

File = new File
{
    CreatedByUserId = _context.AspNetUsers.SingleOrDefault(u => u.UserName == "System").Id,
    CreatedDateTime = DateTime.UtcNow
}

return File

0 个答案:

没有答案