We have client server application where its using WCF for the communication. How to correctly associate a certificate to a WCF Service using app.config. Right now I am defining the certificate in the app.config as follows on the server;
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<serviceCertificate findValue="5b92cf508b894aec82074514954185ecd78b654a" storeLocation="LocalMachine" storeName="Root" x509FindType="FindByThumbprint" />
</serviceCredentials>
</behavior>
</behaviors>
In the client side, I am assigning the certificate programmatically as follows,
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates = store.Certificates.Find(
X509FindType.FindByThumbprint, "5b92cf508b894aec82074514954185ecd78b654a", true); //I am seeing the certificate correctly. Please see the screenshot below.
InstanceContext context = new InstanceContext(callback);
this.SystemService = new SystemServiceClient(context, tcpBinding, tcpAddress);
this.SystemService.ClientCredentials.ClientCertificate.Certificate = certificates[0];
When debugging it correctly shows the certificate as follows on the client side,
When trying to establish a connection with the WCF service using the line string[] lstIFs = this.ServerConnection.NetworkService.GetNetworkInterfaces();
, we get an error as follows,