1

I have a problem making HTTP calls to an external API using HTTPS (TLS 1.2) from my .NET Core 1.1 web application. The application runs fine locally, but when deployed to Azure app services I get the following exception:

exceptionMessage:An error occurred while sending the request. exceptionType:System.Net.Http.HttpRequestException 

The inner exception is:

innerExceptionMessage:A security error occurred innerExceptionType:System.Net.Http.WinHttpException 

The strange thing is that I don't get this exception on all requests to the external API, it only happens some times.

I noticed that similar issues have been discussed in other SO posts, but most of them have been about self-signed certificates. In my case, the remote server is using a certificate signed by GeoTrust.

All calls are being made with System.Net.Http.HttpClient

Related:

Full stack trace:

{ exceptionType: "System.Net.Http.HttpRequestException", innerException: { innerStacktrace: " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at System.Net.Http.WinHttpHandler.<StartRequest>d__105.MoveNext()", innerExceptionMessage: "A security error occurred", innerExceptionType: "System.Net.Http.WinHttpException" }, stacktrace: " at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.ApiService.<PostResourceToApiAsync>d__5`1.MoveNext() in C:\projects\integration\src\Integration\Services\ApiService.cs:line 112 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.AccountService.<NotifyOwnerAsync>d__12.MoveNext() in C:\projects\integration\src\Integration\Services\AccountService.cs:line 115 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.AccountService.<CreateAccountAsync>d__9.MoveNext() in C:\projects\integration\src\Integration\Services\AccountService.cs:line 66 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Services.PartnerService.<CreateAccountAsync>d__11.MoveNext() in C:\projects\integration\src\Integration\Services\PartnerService.cs:line 100 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Integration.Controllers.AccountsController.<Create>d__7.MoveNext() in C:\projects\integration\src\Integration\Controllers\AccountsController.cs:line 92 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__25.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextExceptionFilterAsync>d__24.MoveNext()", exceptionMessage: "An error occurred while sending the request." } 
5
  • could you also get the stack trace as well ? Also if possible,try to take a [system.net tracing ](learn.microsoft.com/en-us/dotnet/framework/network-programming/…) Commented Jul 4, 2017 at 9:22
  • I've added the full stack trace but I haven't got the system.net tracing to work yet. Commented Jul 4, 2017 at 10:31
  • Please follow this to enable system.net tracing blogs.msdn.microsoft.com/benjaminperkins/2017/01/05/… Commented Jul 4, 2017 at 11:44
  • I followed that guide but there is no file written to the directory specified in the initializeData property. Maybe the approach described in the article isn't applicable for .NET Core applications. Commented Jul 4, 2017 at 11:53
  • That may be right,i have not tried on .net core application.I will check it and update this thread Commented Jul 4, 2017 at 11:56

1 Answer 1

0

I think the issue that I've seen is due to this bug: https://github.com/dotnet/corefx/issues/7812

That explains why I only saw this when the application was deployed to a web appp in Azure, since that is running Windows Server 2012. The real fix for this would be to upgrade to Windows Server 2016 but that is currently not supported for web apps in Azure :-(

My workaround for now is just a simple re-try mechanism which seem to work fairly well.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.