Michael Commons
Michael Commons

Reputation: 822

Client certificate to connected service .net core

I have a .net core 2 API where i've connected a WCF service (which is an email sender); The service is hosted on IIS with HTTPS and require SSL; I want to pass the client certificate from the api whenever i make the connection to the email service. I think the only solution is to change the reference.cs file (which is not the best practice and i have no idea what should i change)

This is my startup.cs file; I made this because i want a dynamic url based on the environment

   services.AddTransient<IEmailService, EmailServiceClient>((serviceProvider) =>
        {
            var configuration = serviceProvider.GetService<IConfiguration>();

            var url = configuration.GetValue<string>("EmailServiceUrl");

            return new EmailServiceClient(EmailServiceClient.EndpointConfiguration.WSHttpBinding_IEmailService, url);
        });

Any suggestion

Upvotes: 0

Views: 1720

Answers (1)

Michael Commons
Michael Commons

Reputation: 822

I've added the client certificate to the ServiceClient after i instante it in the Startup.cs

            client.ClientCredentials.ClientCertificate.SetCertificate(System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine,
                System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.X509FindType.FindByThumbprint, "thumbprint");

Upvotes: 1

Related Questions