Monday, 14 October 2013

Message Security using Certificate Client Credential in WCF

Message Security using Certificate Client Credential in WCF

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 steps to implement message security using Certificate Client Credential:-

Step 1:-

Go to the IIS Server by typing inetmgr in run

Step 2:-

Click on server certificate

Figure 1

Step 3:-

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

Figure 2

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

Figure 3

Step 4:-

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

Step 5:-

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 behavior tag inside the service behavior 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 and you will the get following window:-

Figure 4

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 and you will get following output
(I simply return string from service to the client)

Figure 5

if you find any problem to run this code kindly mail me your error at


  1. Internship & Recruitment Program for MCA students
    Webtrackker also provide the 6 Month/ weeks industrial training / Internship & Recruitment Program for MCA students in Java, dot net, Web designing, web developments, Angular.js, Node.js, Hybrid apps, computer networking, Plc Scada, Auto cad, All modules in ERP sap, sap mm, sap fico. Php, Oracle Dba, networking etc for MCA, BCA, B.Tech Students.
    Webtrackker Technologies
    B-47, Sector- 64
    Noida- 201301
    Phone: 0120-4330760, 8802820025
    Email: Info@Webtrackker.Com

  2. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    digital marketing company in chennai

  3. I just see the post i am so happy to the communication science post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be replay for your great thinks and I hope you post again soon.

    digital marketing course in chennai
    software testing training in chennai

  4. I read a weblog, I hope that it doesn't sadden me as much as this one. I’m talking about, I know it was my selection to read, but I actually thought you'd have something interesting to say. Great work admin..
    Office Interiors in Chennai
    Home Interior Decorators in Chennai

  5. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.
    SEO Company in India

  6. Your thinking toward the respective issue is awesome also the idea behind the blog is very interesting which would bring a new evolution in respective field. Keep update more information.
    Industrial Architecture
    Warehouse Architect
    Civil Engineering Consultants
    Office Interiors in Chennai

  7. Fertility is the natural capability to produce offspring. As a measure, fertility rate is the number of offspring born per mating pair, individual or population.Human fertility depends on factors of nutrition, sexual behavior, consanguinity, culture, instinct, endocrinology, timing, economics, way of life, and emotions.Greate thinks of a fertility center for humans.

    Fertility Center in OMR

  8. I have really happy to these reading your post. This product control and maintenance of our health.The daily routine can assist you weight lose quickly and safely.My life is completely reworked once I followed this diet.I feeling nice concerning myself.

    Herbalife in Chennai
    Herbalife Nutrition Products
    Nutrition centers in Chennai
    Weight Loss in Chennai
    Weight Gain in Chennai


  9. BIG DATA Technologies provides you with a state of the art software which combines modern GPU technology (Graphic Processing Units) with the best practices in today’s Big Data platforms, providing up to 100x faster insights from data.
    Bigdata Training in Chennai OMR

  10. This comment has been removed by the author.

  11. thanks for your post Here is STUCORNER the Best DIGITAL marketing training institute in delhi you can visit their site:Stucorner