dotnet / dotnet/wcf

HTTP request is unauthorized with client authentication scheme 'Ntlm

Open
#5,515 7 comments 0 reactions 1 assignee Claimed by @mconnew View on GitHub
triaged
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

**Describe the bug**

I am developing a ASP service that is executing an SSRS report via WCF and I encountered this error when UnitTesting the WCF project in Visual Studio 2022.
These test used to work okay, whenever new versions of `System.ServiceModel.XXX` Nuget packages are released, I recieve the following error:

```
The CustomBinding on the ServiceEndpoint with contract 'ReportingService2005Soap' lacks a TransportBindingElement. Every binding must have at least one binding element that derives from TransportBindingElement
```

This forces me to update the Nuget packages to the latest and resolves the issue.
However this time I have updated the Nuget packages to verson **8** and I receive a new error when I run the unit tests:

```
'The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'.'
```

My code has not changed, I have only updated the Nuget packages, so I am wondering if there is a change in version 8 that would cause this issue or a new property that needs to be set?

This is my service:

```csharp
private RSService.ReportingService2005SoapClient _rs = new RSService.ReportingService2005SoapClient(RSService.ReportingService2005SoapClient.EndpointConfiguration.ReportingService2005Soap);
```

I am setting the binding in my constructor:

```csharp
var binding = _rs.Endpoint.Binding as BasicHttpBinding;
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
```

And the credential just before I call a SOAP method:

```csharp
rs.ClientCredentials.Windows.ClientCredential = new NetworkCredential("****", "****");
```

I have done searches and the issue seems similar to https://github.com/dotnet/wcf/issues/3694 but not quite the same.
My `.csproj`:

```xml


net8.0
enable
enable









```

Any help would be greatly appreciated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.