【发布时间】:2021-03-26 10:04:24
【问题描述】:
我有一些调用 WCF 服务的 .NET Core 3.1 代码:
var endpoint = new EndpointAddress("https://my-url");
var client = new MyClient(MyClient.EndpointConfiguration.basicHttpBindingMy, endpoint);
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("api username", "api password");
client.GetStuff();
Visual Studio 自动生成的绑定代码:
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
result.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
问题
这在 Windows 上完美运行,但在 Linux 容器中运行时(基于 docker 映像 mcr.microsoft.com/dotnet/runtime:3.1),我收到此错误:
System.ServiceModel.Security.MessageSecurityException:HTTP 请求未使用客户端身份验证方案“协商”。 从服务器收到的身份验证标头是“协商, NTLM'。
尝试的解决方案
我尝试了在其他地方找到的以下解决方案,但它们似乎对此没有任何影响:
-
在 main() 中调用:
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false); -
添加到 Dockerfile:
apt-get update && apt-get install -y --no-install-recommends apt-utils gss-ntlmssp
【问题讨论】:
-
请帮忙分享您的
web.config和app.config文件 -
@Ashok 我没有任何 app.config 文件。这是一个 NET Core 3.1 控制台应用程序。
-
确认 .NET 5.0 中存在同样的问题
-
既然你找到了解决方案,你可以取消赏金吗?