Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

An easy way to use certificates for WCF security

, 30 Apr 2007
An easy solution to use certificates on Windows Communication Foundation loading the certificates from files
wcfcertificates.zip
WCFCertificates
Bin
DevAge.ServiceModel.dll
Client
Client.cer
Client.pfx
Client.pvk
Properties
Service References
MathService.map
DevAge.ServiceModel
Configuration
Properties
Documents
Server
App_Code
App_Data
Client.cer
Server.cer
Server.pfx
Server.pvk
Bin
DevAge.ServiceModel.dll
MathService.svc
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <!-- Add devage.serviceModel section handler -->
    <section name="devage.serviceModel" 
             type="DevAge.ServiceModel.Configuration.Section, DevAge.ServiceModel" />
  </configSections>

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="binding1" >
          <security mode="Message">
            <!-- Set the client authentication mode -->
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="behavior1">
          <clientCredentials>
            <serviceCertificate>
              <!-- Set certificateValidationMode to None to don't check if the server certificate is trusted, so you can use self signed certificate.
                WARNING: Remember to set this property to ChainTrust or PeerOrChainTrust when using a certificate generated from a trusted authority -->
              <authentication certificateValidationMode="None" />
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <client>
      <endpoint address="http://localhost:1281/Server/MathService.svc"
          binding="wsHttpBinding" bindingConfiguration="binding1"
          contract="Client.MathService.IMathService"
          behaviorConfiguration="behavior1"
           name="endpoint1" >
        <identity>
          <!--This is the value used to check the server certificate identity, 
            this value is generated by svcutil -->
          <certificate encodedValue="AwAAAAEAAAAUAAAAAwfY0ncXmYzgHsz867X3N4Q5kqwgAAAAAQAAABICAAAwggIOMIIBd6ADAgECAhByuAGzSzvPmEdkfArwuiwYMA0GCSqGSIb3DQEBBAUAMBwxGjAYBgNVBAMTEUNvbXBhbnlYWVogU2VydmVyMB4XDTA2MTIzMTIyMDAwMFoXDTA5MTIzMTIyMDAwMFowHDEaMBgGA1UEAxMRQ29tcGFueVhZWiBTZXJ2ZXIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALLarFS61iOKmWrKQQpNIeiZRYAzc0SdzA49fWCZrd0Nfm4msUwnlfeQPTgQaZgQYlENTTcvC6gfzWcHl+MtiGFwgh+DCBoSJKADT8MvoQSoiSpDVXYAjNRMvY+d3qRfsSoUSZsKVBHX/DHoSnnQzff1bZDWFDgNfXIMbOskUD3nAgMBAAGjUTBPME0GA1UdAQRGMESAEP0oMSMx9ntey38U4bxjpvGhHjAcMRowGAYDVQQDExFDb21wYW55WFlaIFNlcnZlcoIQcrgBs0s7z5hHZHwK8LosGDANBgkqhkiG9w0BAQQFAAOBgQAz0sHzO2FF0L9eSzE8zQFKhpyS08fPxXhhFZ2wThBBClMN0WwFe1QNaZmmtm3oxKoqHkHoYLzPZ+4rYN8OHdMzi8/yDORIZkYDGYZemDqPT7EijbcLD+ewfnT2sw6K2nsLa73ypUEcKs2AVuo91RqKjSrlh2fQ396K1LitIB0iRQ==" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

  <!-- Specific DevAge.ServiceModel configuration -->
  <devage.serviceModel>
    <!-- List of endPoints each with the relative client certificate 
      to use for authentication. -->
    <endPoints>
      <add contract="Client.MathService.IMathService"
            clientCertificate="Client.pfx" />
    </endPoints>
  </devage.serviceModel>
  
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

About the Author

Davide Icardi
Software Developer
Italy Italy
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140718.1 | Last Updated 30 Apr 2007
Article Copyright 2007 by Davide Icardi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid