我尝试使用 NTLM 身份验证方案连接到 WCF SOAP 服务,在使用 .Net Framework 4.x 时我成功了,但是当我尝试在 .NET Core 2.1 中使用相同服务时却失败了(因为尽管我在代码中设置了 Ntlm,但身份验证方案仍以 Negotiate 的形式发送),我使用的是 fiddler,并附上了一些图片。
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,Negotiate”。)
任何帮助都将非常感谢,谢谢!