NullReferenceException when using proxy server with NTLM authentication and BasicHttpBinding (... and potentially others)
See original GitHub issueWhen using BasicHttpBinding (or potentially others) behind a web proxy that requires authentication, the authenticationScheme cannot be used, as when it comes to opening the http channel, a NullReferenceException is raised in System.Private.ServiceModel.dll when trying to use an uninialized class member.
Root cause: the credential manager only gets instantiated when using authentication against the service itsself but the proxy authentication, which actually can be different (and is in most cases in large enterprise scenarios) is being ignored, even if passed by the used binding.
Code to reproduce:
private Binding CreateBinding()
{
BasicHttpBinding binding = new BasicHttpBinding();
if (this.ServiceUri.OriginalString.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
{
binding.Security.Mode = BasicHttpSecurityMode.Transport;
}
else
{
binding.Security.Mode = BasicHttpSecurityMode.None;
}
binding.CloseTimeout = TimeSpan.FromSeconds(2);
binding.OpenTimeout = TimeSpan.FromSeconds(5);
binding.ReceiveTimeout = TimeSpan.FromMinutes(2);
binding.SendTimeout = TimeSpan.FromMinutes(2);
binding.MaxBufferSize = Int32.MaxValue;
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.AllowCookies = true;
CustomBinding customBinding = new CustomBinding(binding);
if (this.IsProxyEnabled)
{
HttpTransportBindingElement httpElement = customBinding.Elements.Find<HttpTransportBindingElement>();
httpElement.UseDefaultWebProxy = false;
httpElement.ProxyAddress = new Uri($"http://{this.ServiceSettings.ProxyHostname}:{this.ServiceSettings.ProxyPort}");
httpElement.ProxyAuthenticationScheme = AuthenticationSchemes.Ntlm; // produces NullReferenceException in WCF client (master) during execution
//httpElement.AuthenticationScheme = AuthenticationSchemes.Ntlm; // nicht richtig - das hier wäre für die authentifizierung am Webservice selbst
httpElement.BypassProxyOnLocal = false;
}
return customBinding;
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
System.InvalidOperationException: The required ...
NullReferenceException when using proxy server with NTLM authentication and BasicHttpBinding (... and potentially others ) #4557.
Read more >c# - How to setup proxy Credentials using ...
I coded a WCF Service using HttpTransportBindingElement in conjunction with IIS on port 80. The code works fine as long as no proxy...
Read more >active directory - NTLM through proxy server
NTLM is connection orientated and since there's no direct connection between you and the webserver when you use the proxy, so NTLM fails....
Read more >Can't consume web services via an HTTP proxy server
This article provides a resolution to fix the error that occurs on a .NET client that consumes a Web service via an HTTP...
Read more >All client browsers repeatedly asking for NTLM ...
This is repeatable with some clients running through my proxy server, but in other cases it does not happen at all. In the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mconnew, sorry in advance for mess with this 2 prev PR - I really don’t know how to purge these artifacts from issue history. But #4563 really fixes issue with Proxy with Basic auth and gets relief with all this nightmares about configuring binding proxy.
The exception call stack for #4562 is here:
httpElement.ProxyAuthenticationScheme = AuthenticationSchemes.Basic; // produce UsernameSecurityToken error