.net-core - .NET Core 控制台应用程序 - SSL 连接错误

标签 .net-core nest asp.net-core-2.0

上下文:

我有一个 n 层动态应用程序,当前在应用程序启动时构建其弹性索引。

虽然这可以让事情顺利进行,但我更喜欢有一个小的 CLI 应用程序/util,我可以稍后在一些脚本中重用它,或者如果我需要做一些事情,比如创建一个新实例、播种模拟数据等。

问题:

当我在控制台应用程序中使用与 dotnetcore Web 应用程序启动时完全相同的代码时,出现以下问题:

Invalid NEST response built from a unsuccessful low level call on PUT: /jobs-ng
# Audit trail of this API call:
 - [1] BadRequest: Node: https://localhost:9200/ Took: 00:00:01.3948230
# OriginalException: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: SSL connect error
   at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error)
   at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference`1 easyWrapper, CURLcode messageResult)
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Users\russ\source\elasticsearch-net-5.x\src\Elasticsearch.Net\Connection\HttpConnection-CoreFx.cs:line 78
# Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response:
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>

其他信息:

目前我的 ElasticClient 类只能这样设置:

 var uri = new Uri("https://localhost:9200");
 services.AddSingleton(new ElasticClient(new ConnectionSettings(uri)));

...因此我没有在任何地方明确设置证书。 (到目前为止还没有要求)

我最好的猜测是, native 控制台应用程序缺少默认 Web 应用程序项目提供的某些内容,但至于什么,我不知道?

我已根据错误日志设置了 DisableDirectStreaming(),但仍然没有任何变化。

我相信这可能是 .Net Core 中的一个错误,但我希望有人知道解决方法,或者暂时解决这个问题(除了让此代码成为我们应用程序启动的一部分? (这就是我当前的工作解决方案))

最佳答案

目前在 dotnet-core 项目的 CURL 实现/使用/OSX 上的 CURL 中存在一个已记录的问题...您明白了。它似乎已在 1.1 中修复,但由于我在 2.0 上(并且我已尝试在各个 github 线程上尝试所有建议的修复,但没有成功),我无法验证该修复是否有效。

因此答案:

有一个bug这导致当前无法在 OSX 上运行。

解决方法:

由于我的控制台应用程序/cli-tool 将在我们的应用程序网络/同一计算机实例内部临时运行,因此理论上该实用程序不需要 HTTPSHTTP 应该足够了。 (一旦我进行了更改,代码就全面运行良好)

关于.net-core - .NET Core 控制台应用程序 - SSL 连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47015634/

相关文章:

elasticsearch - Elastic Search NEST-当我们提到类型名称时,搜索不返回任何记录

aws-lambda - 从 Visual Studio Team Services 部署到 AWS Lambda,找不到 Dotnet Lamba

c# - HostingEnvironment 不包含 IsHosted 的定义

c# - Elasticsearch NEST

node.js - NestJS 如何将自定义 Logger 添加到自定义 ExceptionFilter

asp.net-core - 无法加载 csproj 的项目文件

c# - System.InvalidOperationException : 'A path base can only be configured using IApplicationBuilder.UsePathBase().'

mongodb - 使用 DotNet Core 的 MongoDB 驱动程序时出现异常

c# - 无法为基本属性翻译 LINQ 表达式

azure - 部署到 azure 应用服务时站点不显示