1

I was trying to connect to a WCF SOAP service using NTLM Authentication Scheme, I succeeded at it when using .Net Framework 4.x but when I try to consume the same service in .NET Core 2.1 it fails (because the Authentication scheme is sent as Negotiate despite I set Ntlm in the code), I was using fiddler and I'm attaching some pictures of it.

Net Framework 4.x's Header Net Framework 4.x's Header

Net Core 2.1's Headers

Net Core 2.1's Headers

And this is the source code I'm using .NetCore2.1 and .NetFramework 4.5.x (in which works fine):

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;

The error I'm getting in .NetCore2.1 is:

One or more errors occurred. (The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM, Negotiate'.)

Any help would be really appreciated, thank you!.

dennisbot
  • 950
  • 1
  • 11
  • 22

1 Answers1

0

Please check this thread. Thread contains several workarounds :

// 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
fenixil
  • 2,106
  • 7
  • 13