【发布时间】:2019-09-19 16:33:21
【问题描述】:
我试图使用 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,协商”。)
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
您解决了这个问题吗?
-
否 :(,我使用 .Net 框架应用程序作为代理。
标签: .net .net-core soap-client ntlm ntlm-authentication