In this article I am explaining how to achieve message security using certificate client credential. In my last article I described the message security using user name client credential.

Following are the implementation of message security using Certificate Client Credential:-

Go to the IIS Server by typing inetmgr in run

Click on server certificate

message security in wcf

After opening the server certificate on right panel select the create self-signed certificate

server certificate

Now certificate creation window will be opened. Give a proper name to the certificate and click ok.

		self signed server certificate
		Figure 3

Now create a WCF service. Go to visual studio->New->Website->Wcf Service

Make changes in your web configuration file. Add following binding tag in system.sevicemodel tag. In binding tag add message security and client credential as certificate

          <security mode="Message">
            <message clientCredentialType="Certificate"></message>

now add behaviour tag inside the service behaviour tag and the certificate detail in it which you have created on IIS in the beginning.

            <serviceCertificate storeLocation="LocalMachine" findValue="isha" storeName="My" x509FindType="FindByIssuerName"/>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
Now add service tag 
      <service name="Service">
        <endpoint address="" binding="wsHttpBinding" contract="IService"/>


Now execute the program

Now create the client and add service reference and pass client credential with all the detail of certificate.

	using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

ServiceReference1.ServiceClient svc = new ServiceReference1.ServiceClient();
     svc.ClientCredentials.ClientCertificate.SetCertificate(System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine, System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.X509FindType.FindByIssuerName, "isha");



Now execute the code