我试图使用NTLM身份验证方案连接到WCF SOAP服务,使用.Net Framework 4.x时我成功了,但是当我尝试在.NET Core 2.1中使用相同的服务时,它失败了(因为身份验证尽管我在代码中设置了Ntlm,但该方案仍以协商方式发送),我正在使用提琴手,并附上了一些图片。
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,协商”。)
任何帮助将不胜感激,谢谢!。
答案 0 :(得分:0)
请检查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