【发布时间】:2019-05-15 13:13:43
【问题描述】:
我无法通过在 linux 机器(docker 容器)上运行的 .NET Core 成功调用具有 NTLM 身份验证的 WCF 服务。 不过,相同的代码在 Windows 10 上也能完美运行。
我做了什么:
- 将此添加到
ConfigureServices:
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
- 运行
apt-get -y install gss-ntlmssp - 这是调用服务之前的代码:
var client = new WcfServiceSoapClient();
client.Endpoint.Address = new EndpointAddress(settings.Uri);
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = new NetworkCredential
{
Domain = settings.Domain,
UserName = settings.Username,
Password = settings.Password
};
var binding = (BasicHttpBinding)client.Endpoint.Binding;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Ntlm;
如前所述,这在 Windows 10 上运行良好。在 Linux 上记录以下错误:
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM, Negotiate'.
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
问题是:为什么它在 linux 上仍然失败?
【问题讨论】:
-
服务器使用哪个绑定,你是使用微软wcf web service reference provider生成客户端代理类吗?您是否尝试使用 ChannelFactory 来调用服务? docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/…
-
@AbrahamQian 添加连接服务时,我在 VS2019 中使用了生成的 WSDL 文件,该文件由 WCF 服务的开发人员交给我。我没有使用 ChannelFactory,因为我没有 VS WCF 工具生成的接口。
-
我设法使用了 ChannelFactory(由于缺少“I”后缀而没有看到界面),但在 Linux 上我遇到了同样的错误:
System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM, Negotiate'. -
最后我们切换到基本身份验证。 This issue should be fixed in .NET Core 3.
标签: c# linux wcf .net-core ntlm