3

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
  • 131
  • 4
  • Did you manage to find a solution for this? I am having a very similar problem – Henrik Nov 24 '20 at 09:50
  • Today i had the same issue when trying to connect to an existing wcf service from a console application written in .net core 5. The only solution we could find for now was to remove the negotiate provider in IIS for the wcf service. But tbh i would rather have seen a client only fix for this. – Dbuggy May 25 '21 at 15:07

0 Answers0