Click here to Skip to main content
12,243,182 members (21,105 online)
Click here to Skip to main content

Tagged as

Stats

37.2K views
2.7K downloads
25 bookmarked
Posted

Use Mutual SSL Authentication in WCF

, 16 Mar 2012 CPOL
How to configure and use Mutual SSL Authentication in WCF.
HttpsBindingDemo
MyClient
Properties
Service References
SecuredServices
configuration.svcinfo
configuration91.svcinfo
EchoService.wsdl
item.disco
Reference.svcmap
MyService
Properties
NetTcpBindingDemo
MyClient
Properties
Service References
SecuredServices
configuration.svcinfo
configuration91.svcinfo
EchoService.wsdl
Reference.svcmap
MyService
Properties
<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="EchoServiceBehavior">
          <serviceCredentials>
            <serviceCertificate storeLocation="LocalMachine" x509FindType="FindByIssuerName" findValue="MyRootCA" />
          </serviceCredentials>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="False" 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="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="MutualSslBinding" closeTimeout="00:01:00" openTimeout="00:01:00" 
                 receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" 
                 bypassProxyOnLocal="false" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" 
                 transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
                        maxNameTableCharCount="2147483647"/>
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="HttpsBindingDemo.EchoService" behaviorConfiguration="EchoServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="https://demopc.mydomain.com:56111/EchoService/"/>
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MutualSslBinding" contract="HttpsBindingDemo.IEchoService">
        </endpoint>
      </service>
    </services>
    <!-- If this service is hosted in IIS Environment -->
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add service="HttpsBindingDemo.EchoService, HttpsBindingDemo.EchoService" relativeAddress="EchoService.svc" />
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.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 Code Project Open License (CPOL)

Share

About the Author

Elvin Cheng
Singapore Singapore
Elvin Cheng is currently living in Woodlands, Singapore. He has been developing applications with the .NET Framework, using C# and ASP.NET since October 2002. Elvin specializes in building Real-time monitoring and tracking information system for Semi-conductor manufacturing industry. During his spare time, he enjoys reading books, watching movie and gym.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 16 Mar 2012
Article Copyright 2012 by Elvin Cheng
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid