【问题标题】:Getting Authentication Negotiate instead of NTLM while consuming SOAP WCF Service in Net.Core 2.1在 Net.Core 2.1 中使用 SOAP WCF 服务时获取身份验证协商而不是 NTLM
【发布时间】:2019-09-19 16:33:21
【问题描述】:

我试图使用 NTLM 身份验证方案连接到 WCF SOAP 服务,我在使用 .Net Framework 4.x 时成功了,但是当我尝试在 .NET Core 2.1 中使用相同的服务时它失败了(因为身份验证尽管我在代码中设置了 Ntlm,但方案仍以协商的形式发送),我使用的是提琴手,我正在附上它的一些图片。

Net Framework 4.x 的头文件

Net Core 2.1 的标头

这是我正在使用 .NetCore2.1 和 .NetFramework 4.5.x 的源代码(其中工作正常):

System.ServiceModel.Channels.CustomBinding binding = new System.ServiceModel.Channels.CustomBinding();
System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
binding.Elements.Add(textBindingElement);
System.ServiceModel.Channels.HttpsTransportBindingElement httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement();
httpsBindingElement.AllowCookies = true;
httpsBindingElement.MaxBufferSize = int.MaxValue;
httpsBindingElement.MaxReceivedMessageSize = int.MaxValue;
httpsBindingElement.AuthenticationScheme = System.Net.AuthenticationSchemes.Ntlm;
binding.Elements.Add(httpsBindingElement);
return binding;

_client.ClientCredentials.Windows.ClientCredential.Domain = "domain";
_client.ClientCredentials.Windows.ClientCredential.UserName = "username";
_client.ClientCredentials.Windows.ClientCredential.Password = "password";
_client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

我在 .NetCore2.1 中遇到的错误是:

发生了一个或多个错误。 (HTTP 请求未经授权 客户端身份验证方案“Ntlm”。身份验证标头 从服务器收到的是“NTLM,协商”。)

任何帮助将不胜感激,谢谢!

【问题讨论】:

  • 您解决了这个问题吗?
  • 否 :(,我使用 .Net 框架应用程序作为代理。

标签: .net .net-core soap-client ntlm ntlm-authentication


【解决方案1】:

请查看this thread。线程包含几个解决方法:

// https://github.com/dotnet/wcf/issues/2923#issuecomment-408341667
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

// https://github.com/dotnet/wcf/issues/2923
ConnectionClose = false
ExpectContinue = false

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 2014-08-18
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多