提供的 URI 方案“https”无效;.Net Core 3.1 中预期的“http”

Pil*_* 77 2 wcf web-services asp.net-core

我们开发了一个 .Net Core 3.1 应用程序,它使用 WCF Web 服务(也是我们开发的)。在我们的办公室,一切正常。\n我们在开发中不\xc2\xb4t 使用 SSL,但在生产服务器中使用 SSL。\n在生产中,当应用程序尝试使用 Web 服务时,会收到下一个错误

\n

[500].System.ArgumentException:\n提供的 URI 方案“https”无效;预期为“http”。(参数“via”)位于 System.ServiceModel.Channels.TransportChannelFactory`1.ValidateScheme(Uri via) ....

\n

\xc2\xbf如何将 http 调用“转换”为 https?\n我们找到了有关 .net 4.5 的信息,但在 .net core 3.1 中没有找到

\n

PD:我们可以\xc2\xb4t 从我们的办公室到达生产 wsdl

\n

小智 8

在您的 web.config 文件中。
更改自

<security mode="None">
Run Code Online (Sandbox Code Playgroud)

<security mode="Transport">
Run Code Online (Sandbox Code Playgroud)

或者在代码中设置

System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
...
binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
...
Run Code Online (Sandbox Code Playgroud)

此更改将允许您使用 https 而不是 http。