kip*_*oep 6 c# linux wcf ntlm .net-core
我无法从 Linux 盒子(docker 容器)上运行的 .NET Core 成功调用具有 NTLM 身份验证的 WCF 服务。不过,相同的代码在 Windows 10 上完美运行。
我做了什么:
ConfigureServices:AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
Run Code Online (Sandbox Code Playgroud)
apt-get -y install gss-ntlmsspvar 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;
Run Code Online (Sandbox Code Playgroud)
如前所述,这在 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)
Run Code Online (Sandbox Code Playgroud)
问题是:为什么在linux上仍然失败?
小智 5
我遇到了同样的问题,并且在 net core GitHub 上的人的帮助下解决了它。
本质上net core使用底层操作系统来处理http调用。之前,在 Linux 上使用了 libCurl,但较新的 SocketsHttpHandler 使用 gss,它不支持 ntlm(至少在“microsoft/dotnet:2.2-aspnetcore-runtime-stretch-slim”映像中不支持)。
要解决此问题,您需要使用 docker 文件在容器中安装额外的库。就在之后
来自 microsoft/dotnet:2.2-aspnetcore-runtime-stretch-slim
(或者你使用的任何图像)
在下一行添加以下内容:
运行 apt-get update && apt-get install -y --no-install-recommends apt-utils gss-ntlmssp
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
6025 次 |
| 最近记录: |