Click here to Skip to main content
11,437,397 members (34,848 online)
Click here to Skip to main content
Add your own
alternative version

An easy way to use certificates for WCF security

, 30 Apr 2007 MIT
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace DevAge.ServiceModel.Configuration
{
    /*
     * 
     *  Here a typical configuration:
        <configSections>
            <!-- Add devage.serviceModel section handler -->
            <section name="devage.serviceModel" type="DevAge.ServiceModel.Configuration.Section, DevAge.ServiceModel" />
        </configSections>
        ...........................
     
        <!-- Specific DevAge.ServiceModel configuration used to set the client valid certificates and server certificate 
         This is a server configuration -->
        <devage.serviceModel>
            <!-- List of service type each with the relative server certificate and client certificate list -->
            <services>
              <add name="MathService" 
                    serverCertificate="App_Data\Server.pfx"
                    clientCertificates="App_Data\Client1.cer, App_Data\Client2.cer"
                    />
            </services>
        </devage.serviceModel>

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

    /// <summary>
    /// The DevAge.ServiceModel conficuration section handler.
    /// Contains the list of certificates files to use.
    /// </summary>
    public class Section : ConfigurationSection
    {
        public static Section GetSection()
        {
            Section section =
                (Section)ConfigurationManager.GetSection("devage.serviceModel");

            return section;
        }

        [ConfigurationProperty("services")]
        public ServiceCollection Services
        {
            get { return this["services"] as ServiceCollection; }
        }

        [ConfigurationProperty("endPoints")]
        public EndPointCollection EndPoints
        {
            get { return this["endPoints"] as EndPointCollection; }
        }
    }
}

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

Share

About the Author

Davide Icardi
Software Developer
Italy Italy
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150428.2 | Last Updated 30 Apr 2007
Article Copyright 2007 by Davide Icardi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid