Skip to content

.NET Core (8.0) WFC Client application getting exception "The HTTP request was forbidden with client authentication scheme 'Anonymous'" #5843

@dikumar38853

Description

@dikumar38853

Client Implementation: It is implemented in .NET 8.0

var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var endpoint = new EndpointAddress("my end point");

var channelFactory = new ChannelFactory<"My Contract">(binding, endpoint);
channelFactory.Credentials.ClientCertificate.Certificate =
new X509Certificate2(@"certificate path", "certificate pwd");
var proxy = channelFactory.CreateChannel();
try
{
var response = proxy.PingDevice();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Below are the NuGet Packages referenced in my WFC Client Application:

<PackageReference Include="System.ServiceModel.Duplex" Version="6.0.0" />
<PackageReference Include="System.ServiceModel.Federation" Version="6.0.0" />
<PackageReference Include="System.ServiceModel.Http" Version="8.1.2" />
<PackageReference Include="System.ServiceModel.Primitives" Version="8.1.2" />
<PackageReference Include="System.ServiceModel.NetNamedPipe" Version="8.1.2" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="8.1.2" />
<PackageReference Include="System.ServiceModel.Security" Version="6.0.0" />

When I tried to troubleshoot it then I found that RemoteCertificate is coming null at the server side, due to that it is getting forbidden error.

and same code if I use in .NET Framework 4.8 then it works fine:
RemoteCertificate coming the correct certification due to that it works


My Service Application's binding configuration is:

<basicHttpBinding>
  <binding name="SSLClientCertificate" maxReceivedMessageSize="2100000000">
    <readerQuotas maxStringContentLength="2100000000" maxBytesPerRead="2100000000" />
    <security mode="Transport">
      <transport clientCredentialType="Certificate" />
    </security>
  </binding>
</basicHttpBinding>

Below is the startup.cs implementation at service side where I can see that ClientCertificate is coming null.

public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app.Use(async (context, next) =>
    {
        var logger = context.RequestServices.GetRequiredService<ILogger<Startup>>();
        var cert = **context.Connection.ClientCertificate;**
        if (cert == null)
        {
            logger.LogWarning("No client certificate received for request to {Path}", context.Request.Path);
        }
        else
        {
            logger.LogInformation("Client certificate received: Subject={Subject}, Thumbprint={Thumbprint}", cert.Subject, cert.Thumbprint);
        }
        await next();
    });

    base.Configure(app, env);
}

Please suggest be if i have missed anything in my .NET 8.0 Client implementation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions