Additional configuration required since upgrading packages to version 4.9.0.
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
Since upgrading WCF client packages to version 4.9.0 the following error is thrown when trying to connect to a WCF service:
> System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate, NTLM'.
In previous versions (4.8.1 and earlier) registering the WCF client for dependency injection was achieved the following way:
```
var address = configuration.GetValue("WcfServiceUrl");
services.AddScoped(opt =>
{
var client = new WcfServiceClient(WcfServiceClient.EndpointConfiguration.IWcfService, address);
client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
return client;
});
```
_Note: `IWcfService` and `WcfServiceClient` are auto-generated by the Connected Service tool._
This exception can be fixed with some additional configuration when creating the WCF service client in Asp.Net Core project:
```
var address = configuration.GetValue("WcfServiceUrl");
services.AddScoped(opt =>
{
var client = new WcfServiceClient(WcfServiceClient.EndpointConfiguration.IWcfService, address);
client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
var binding = client.Endpoint.Binding as BasicHttpBinding;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Ntlm;
return client;
});
```
**Expected behavior**
Up until version 4.9.0 the additional configuration of `ClientCredentialType` and `ProxyCredentialType` was not necessary.
I'm not sure if this change qualifies as a bug, but previous versions required less configuration.
It seems that previous versions were able to negotiate authentication type automatically.
**Additional context**
In our company we have a local WCF service that other Asp.Net Core projects communicate with. We add a reference to this WCF service through the Visual Studio 2022 "Connected Services" dialog.
The WCF service authenticates users by using NTLM.
Contributor guide
Assessment
This issue has not been assessed yet.