Setting up Client Certificate Authentication for WCF Service hosted as an Azure Web App

Published 04-16-2021 03:18 PM 1,033 Views
Microsoft

Recently I worked on a scenario where we had to set up client cert authentication for WCF service hosted as an App service in Azure: We followed the below steps to achieve the same and was able to parse the client certificate in service end using custom certificate validator:

 

Here I have highlighted in detail the steps of how to create and publish a WCF Service with Client Certificate enabled in Azure Web App.

 

Create an Azure Web App:

===========================

 

  1. Navigate to the Azure Portal and login with your Azure account and click on App services.
  2. Click on Add Web Apps and enter the details for Name, Subscription, Resource Group, OS and click Create.
  3. The Web App with name WCFCLIENTCERTSAMPLE is created at my end.

 

Deploying the WCF service to the Web App:

======================================

 

We will be able to publish the created WCF Service or any other type of application directly into the created Web APP.

 

  1. Open Visual studio and create a new project by selecting WCF service application as the project type and name it as CertForAppServiceInAzure.
  2. Let the Default generated code be in the operation contract and Service class for the sample. Modify it according to requirement. I modified it to print the certificate subject passed later:

 

IService1.cs:
[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);
    }

 

Service1.cs:

 

public class Service1 : IService1
    {
        public static string str { get; set; }
        public string GetData(int value)
        {
           return string.Format(str+ value);
       } }

 

 

  1. We need to make the following changes in the Service’s web config inside system.servicemodel section to enable client cert authentication:
  2. In the binding at my end I have used basicHttpsBinding and enabled the security mode as Transport with clientCredentialType as Certificate.
    <system.serviceModel>
        <bindings>
          <basicHttpsBinding>
            <binding name="CertBind">
              <security mode="Transport">
                <transport clientCredentialType="Certificate"/>
              </security>
            </binding>
          </basicHttpsBinding>
        </bindings>
        <services>
          <service name="CertForAppServiceInAzure.Service1">
            <endpoint address="" binding="basicHttpsBinding"  bindingConfiguration="CertBind" contract="CertForAppServiceInAzure.IService1"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
              <serviceCredentials>
                <clientCertificate>
                  <authentication certificateValidationMode="Custom" customCertificateValidatorType="CertForAppServiceInAzure.MyX509CertificateValidator, CertForAppServiceInAzure"/>
                  
                </clientCertificate>
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https"/>
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>
    ​

 

 

 

Note: I have defined the client certificate validator in the service end as a custom validator so that I can verify if the client certificate is fetched in service end and parse the client certificate details. You can ignore step 5 if you are not using custom validator.

 

  1. To add the custom validator class, Create a Class file named MyX509CertificateValidator.cs in the service end with the below code to read the client certificate sent by the client and print the subject details (You can add your own condition check).

 

using System;
using System.IdentityModel.Selectors;
using System.Security.Cryptography.X509Certificates;

namespace CertForAppServiceInAzure
{
 public class MyX509CertificateValidator : X509CertificateValidator
    {
        public override void Validate(X509Certificate2 certificate)
        {
            // Check that there is a certificate.
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }
            Service1.str = certificate.Subject;
            }
    }
}

 

 

         

  1. Right Click on your Project and select Publish, Select the Publish Location as Azure App Service.
  2. Select the Subscription, Resource Group and App service name from the dropdown which you have created on Azure and select Finish to publish the WCF service directly to the created Azure Web App.
  3. Browse the Service Over the Azure App service public URL https://wcfclientcertsample.azurewebsites.net/Service1.svc
  4. We get the below error:

Meghali_0-1618610552139.jpeg

 

 

Enable Client certificate for the same App published in Azure:

=============================================

 

  1. Run the below command to enable the Client certificate for the Azure Web App:

az webapp update --set clientCertEnabled=true --name WCFCLIENTCERTSAMPLE --resource-group MyResGroup

 

Note: Give your App service name and Resource Group name

Meghali_1-1618610552150.jpeg

 

 

  1. To fix the Server Error we add the below section in the Web.config system.WebServer Section and re-publish the same:

 

 

<system.webServer>

    <modules runAllManagedModulesForAllRequests="true"/>

    <security>

      <access sslFlags="Ssl,SslRequireCert,SslNegotiateCert" />

    </security>

    <directoryBrowse enabled="true"/>

  </system.webServer>

 

  1. Browse the application again over the same https://wcfclientcertsample.azurewebsites.net/Service1.svc we get the pop up to select the client certificate we select the client cert and we are able to access the service:

 

Meghali_2-1618610552156.jpeg

 

 

Meghali_3-1618610552160.jpeg

 

 

  1. Now Consume the same service in the client application by creating a test console application project and adding the service Reference by the url https://wcfclientcertsample.azurewebsites.net/Service1.svc
  2. Pass the client certificate details in the web.config and map it with the binding, In my scenario the client app is running on my Windows server. Make Sure the Client certificate is installed on the client machine and present in mmc under Current User.

 

 

<system.serviceModel> 

      <bindings>

        <basicHttpBinding>

          <binding name="BasicHttpsBinding_IService1">

            <security mode="Transport">

              <transport clientCredentialType="Certificate" />

            </security>

          </binding>

        </basicHttpBinding>

      </bindings>

      <client>

        <endpoint address="https://wcfclientcertsample.azurewebsites.net/Service1.svc"

          binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_IService1" behaviorConfiguration="endpointCredentialBehavior"

          contract="ServiceReference1.IService1" name="BasicHttpsBinding_IService1" />

      </client>

      <behaviors>

        <endpointBehaviors>

          <behavior name="endpointCredentialBehavior">

            <clientCredentials>

              <clientCertificate findValue="9c8a3857851e653ff22f0161914a1accf8ac5e76"

                                 storeLocation="CurrentUser"

                                 storeName="My"

                                 x509FindType="FindByThumbprint" />

            </clientCredentials>

          </behavior>

        </endpointBehaviors>

      </behaviors> 

    </system.serviceModel>

 

  1. As in the Service end I have used a custom client certificate validator and for testing purpose I am printing the subject name of the client certificate passed via the custom validator in the service end. Now when we run the client we see the below Console Output.

Meghali_4-1618610552161.jpeg

 

 

 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2276552%22%20slang%3D%22en-US%22%3ESetting%20up%20Client%20Certificate%20Authentication%20for%20WCF%20Service%20hosted%20as%20an%20Azure%20Web%20App%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2276552%22%20slang%3D%22en-US%22%3E%3CP%3ERecently%20I%20worked%20on%20a%20scenario%20where%20we%20had%20to%20set%20up%20client%20cert%20authentication%20for%20WCF%20service%20hosted%20as%20an%20App%20service%20in%20Azure%3A%20We%20followed%20the%20below%20steps%20to%20achieve%20the%20same%20and%20was%20able%20to%20parse%20the%20client%20certificate%20in%20service%20end%20using%20custom%20certificate%20validator%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20I%20have%20highlighted%20in%20detail%20the%20steps%20of%20how%20to%20create%20and%20publish%20a%20WCF%20Service%20with%20Client%20Certificate%20enabled%20in%20Azure%20Web%20App.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECreate%20an%20Azure%20Web%20App%3A%3C%2FP%3E%0A%3CP%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ENavigate%20to%20the%20Azure%20Portal%20and%20login%20with%20your%20Azure%20account%20and%20click%20on%20App%20services.%3C%2FLI%3E%0A%3CLI%3EClick%20on%20Add%20Web%20Apps%20and%20enter%20the%20details%20for%20Name%2C%20Subscription%2C%20Resource%20Group%2C%20OS%20and%20click%20Create.%3C%2FLI%3E%0A%3CLI%3EThe%20Web%20App%20with%20name%20WCFCLIENTCERTSAMPLE%20is%20created%20at%20my%20end.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDeploying%20the%20WCF%20service%20to%20the%20Web%20App%3A%3C%2FP%3E%0A%3CP%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20will%20be%20able%20to%20publish%20the%20created%20WCF%20Service%20or%20any%20other%20type%20of%20application%20directly%20into%20the%20created%20Web%20APP.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EOpen%20Visual%20studio%20and%20create%20a%20new%20project%20by%20selecting%20WCF%20service%20application%20as%20the%20project%20type%20and%20name%20it%20as%20CertForAppServiceInAzure.%3C%2FLI%3E%0A%3CLI%3ELet%20the%20Default%20generated%20code%20be%20in%20the%20operation%20contract%20and%20Service%20class%20for%20the%20sample.%20Modify%20it%20according%20to%20requirement.%20I%20modified%20it%20to%20print%20the%20certificate%20subject%20passed%20later%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EIService1.cs%3A%0A%5BServiceContract%5D%0A%20%20%20%20public%20interface%20IService1%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%5BOperationContract%5D%0A%20%20%20%20%20%20%20%20string%20GetData(int%20value)%3B%0A%20%20%20%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EService1.cs%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Epublic%20class%20Service1%20%3A%20IService1%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20public%20static%20string%20str%20%7B%20get%3B%20set%3B%20%7D%0A%20%20%20%20%20%20%20%20public%20string%20GetData(int%20value)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20return%20string.Format(str%2B%20value)%3B%0A%20%20%20%20%20%20%20%7D%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3EWe%20need%20to%20make%20the%20following%20changes%20in%20the%20Service%E2%80%99s%20web%20config%20inside%20system.servicemodel%20section%20to%20enable%20client%20cert%20authentication%3A%3C%2FLI%3E%0A%3CLI%3EIn%20the%20binding%20at%20my%20end%20I%20have%20used%20basicHttpsBinding%20and%20enabled%20the%20security%20mode%20as%20Transport%20with%20clientCredentialType%20as%20Certificate.%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CSYSTEM.SERVICEMODEL%3E%0A%20%20%20%20%3CBINDINGS%3E%0A%20%20%20%20%20%20%3CBASICHTTPSBINDING%3E%0A%20%20%20%20%20%20%20%20%3CBINDING%20name%3D%22CertBind%22%3E%0A%20%20%20%20%20%20%20%20%20%20%3CSECURITY%20mode%3D%22Transport%22%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CTRANSPORT%20clientcredentialtype%3D%22Certificate%22%3E%3C%2FTRANSPORT%3E%0A%20%20%20%20%20%20%20%20%20%20%3C%2FSECURITY%3E%0A%20%20%20%20%20%20%20%20%3C%2FBINDING%3E%0A%20%20%20%20%20%20%3C%2FBASICHTTPSBINDING%3E%0A%20%20%20%20%3C%2FBINDINGS%3E%0A%20%20%20%20%3CSERVICES%3E%0A%20%20%20%20%20%20%3CSERVICE%20name%3D%22CertForAppServiceInAzure.Service1%22%3E%0A%20%20%20%20%20%20%20%20%3CENDPOINT%20address%3D%22%22%20binding%3D%22basicHttpsBinding%22%20bindingconfiguration%3D%22CertBind%22%20contract%3D%22CertForAppServiceInAzure.IService1%22%3E%3C%2FENDPOINT%3E%0A%20%20%20%20%20%20%3C%2FSERVICE%3E%0A%20%20%20%20%3C%2FSERVICES%3E%0A%20%20%20%20%3CBEHAVIORS%3E%0A%20%20%20%20%20%20%3CSERVICEBEHAVIORS%3E%0A%20%20%20%20%20%20%20%20%3CBEHAVIOR%3E%0A%20%20%20%20%20%20%20%20%20%20%3CSERVICEMETADATA%20httpgetenabled%3D%22true%22%20httpsgetenabled%3D%22true%22%3E%3C%2FSERVICEMETADATA%3E%0A%20%20%20%20%20%20%20%20%20%20%3CSERVICEDEBUG%20includeexceptiondetailinfaults%3D%22false%22%3E%3C%2FSERVICEDEBUG%3E%0A%20%20%20%20%20%20%20%20%20%20%3CSERVICECREDENTIALS%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CCLIENTCERTIFICATE%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CAUTHENTICATION%20certificatevalidationmode%3D%22Custom%22%20customcertificatevalidatortype%3D%22CertForAppServiceInAzure.MyX509CertificateValidator%2C%20CertForAppServiceInAzure%22%3E%3C%2FAUTHENTICATION%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FCLIENTCERTIFICATE%3E%0A%20%20%20%20%20%20%20%20%20%20%3C%2FSERVICECREDENTIALS%3E%0A%20%20%20%20%20%20%20%20%3C%2FBEHAVIOR%3E%0A%20%20%20%20%20%20%3C%2FSERVICEBEHAVIORS%3E%0A%20%20%20%20%3C%2FBEHAVIORS%3E%0A%20%20%20%20%3CPROTOCOLMAPPING%3E%0A%20%20%20%20%20%20%3CADD%20binding%3D%22basicHttpsBinding%22%20scheme%3D%22https%22%3E%3C%2FADD%3E%0A%20%20%20%20%3C%2FPROTOCOLMAPPING%3E%0A%20%20%20%20%3CSERVICEHOSTINGENVIRONMENT%20aspnetcompatibilityenabled%3D%22true%22%20multiplesitebindingsenabled%3D%22true%22%3E%3C%2FSERVICEHOSTINGENVIRONMENT%3E%0A%20%20%3C%2FSYSTEM.SERVICEMODEL%3E%0A%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%3A%20I%20have%20defined%20the%20client%20certificate%20validator%20in%20the%20service%20end%20as%20a%20custom%20validator%20so%20that%20I%20can%20verify%20if%20the%20client%20certificate%20is%20fetched%20in%20service%20end%20and%20parse%20the%20client%20certificate%20details.%20You%20can%20ignore%20step%205%20if%20you%20are%20not%20using%20custom%20validator.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%225%22%3E%0A%3CLI%3ETo%20add%20the%20custom%20validator%20class%2C%20Create%20a%20Class%20file%20named%20MyX509CertificateValidator.cs%20in%20the%20service%20end%20with%20the%20below%20code%20to%20read%20the%20client%20certificate%20sent%20by%20the%20client%20and%20print%20the%20subject%20details%20(You%20can%20add%20your%20own%20condition%20check).%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Eusing%20System%3B%0Ausing%20System.IdentityModel.Selectors%3B%0Ausing%20System.Security.Cryptography.X509Certificates%3B%0A%0Anamespace%20CertForAppServiceInAzure%0A%7B%0A%20public%20class%20MyX509CertificateValidator%20%3A%20X509CertificateValidator%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20public%20override%20void%20Validate(X509Certificate2%20certificate)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20Check%20that%20there%20is%20a%20certificate.%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(certificate%20%3D%3D%20null)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20throw%20new%20ArgumentNullException(%22certificate%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20Service1.str%20%3D%20certificate.Subject%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%225%22%3E%0A%3CLI%3ERight%20Click%20on%20your%20Project%20and%20select%20Publish%2C%20Select%20the%20Publish%20Location%20as%20Azure%20App%20Service.%3C%2FLI%3E%0A%3CLI%3ESelect%20the%20Subscription%2C%20Resource%20Group%20and%20App%20service%20name%20from%20the%20dropdown%20which%20you%20have%20created%20on%20Azure%20and%20select%20Finish%20to%20publish%20the%20WCF%20service%20directly%20to%20the%20created%20Azure%20Web%20App.%3C%2FLI%3E%0A%3CLI%3EBrowse%20the%20Service%20Over%20the%20Azure%20App%20service%20public%20URL%20%3CA%20href%3D%22https%3A%2F%2Fwcfclientcertsample.azurewebsites.net%2FService1.svc%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwcfclientcertsample.azurewebsites.net%2FService1.svc%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EWe%20get%20the%20below%20error%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Meghali_0-1618610552139.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F273447i8E8C4B05712492B4%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Meghali_0-1618610552139.jpeg%22%20alt%3D%22Meghali_0-1618610552139.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EEnable%20Client%20certificate%20for%20the%20same%20App%20published%20in%20Azure%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ERun%20the%20below%20command%20to%20enable%20the%20Client%20certificate%20for%20the%20Azure%20Web%20App%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3Eaz%20webapp%20update%20--set%20clientCertEnabled%3Dtrue%20--name%20WCFCLIENTCERTSAMPLE%20--resource-group%20MyResGroup%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%3A%20Give%20your%20App%20service%20name%20and%20Resource%20Group%20name%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Meghali_1-1618610552150.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F273449i90318351404FAE5D%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Meghali_1-1618610552150.jpeg%22%20alt%3D%22Meghali_1-1618610552150.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%222%22%3E%0A%3CLI%3ETo%20fix%20the%20Server%20Error%20we%20add%20the%20below%20section%20in%20the%20Web.config%20system.WebServer%20Section%20and%20re-publish%20the%20same%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CSYSTEM.WEBSERVER%3E%0A%0A%20%20%20%20%3CMODULES%20runallmanagedmodulesforallrequests%3D%22true%22%3E%3C%2FMODULES%3E%0A%0A%20%20%20%20%3CSECURITY%3E%0A%0A%20%20%20%20%20%20%3CACCESS%20sslflags%3D%22Ssl%2CSslRequireCert%2CSslNegotiateCert%22%3E%3C%2FACCESS%3E%0A%0A%20%20%20%20%3C%2FSECURITY%3E%0A%0A%20%20%20%20%3CDIRECTORYBROWSE%20enabled%3D%22true%22%3E%3C%2FDIRECTORYBROWSE%3E%0A%0A%20%20%3C%2FSYSTEM.WEBSERVER%3E%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%223%22%3E%0A%3CLI%3EBrowse%20the%20application%20again%20over%20the%20same%20%3CA%20href%3D%22https%3A%2F%2Fwcfclientcertsample.azurewebsites.net%2FService1.svc%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwcfclientcertsample.azurewebsites.net%2FService1.svc%3C%2FA%3E%20we%20get%20the%20pop%20up%20to%20select%20the%20client%20certificate%20we%20select%20the%20client%20cert%20and%20we%20are%20able%20to%20access%20the%20service%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Meghali_2-1618610552156.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F273448iD5FAC1FB8BA7554B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Meghali_2-1618610552156.jpeg%22%20alt%3D%22Meghali_2-1618610552156.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Meghali_3-1618610552160.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F273451iA38CC2D867F7CF3C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Meghali_3-1618610552160.jpeg%22%20alt%3D%22Meghali_3-1618610552160.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%224%22%3E%0A%3CLI%3ENow%20Consume%20the%20same%20service%20in%20the%20client%20application%20by%20creating%20a%20test%20console%20application%20project%20and%20adding%20the%20service%20Reference%20by%20the%20url%20%3CA%20href%3D%22https%3A%2F%2Fwcfclientcertsample.azurewebsites.net%2FService1.svc%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwcfclientcertsample.azurewebsites.net%2FService1.svc%20%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EPass%20the%20client%20certificate%20details%20in%20the%20web.config%20and%20map%20it%20with%20the%20binding%2C%20In%20my%20scenario%20the%20client%20app%20is%20running%20on%20my%20Windows%20server.%20Make%20Sure%20the%20Client%20certificate%20is%20installed%20on%20the%20client%20machine%20and%20present%20in%20mmc%20under%20Current%20User.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CSYSTEM.SERVICEMODEL%3E%20%0A%0A%20%20%20%20%20%20%3CBINDINGS%3E%0A%0A%20%20%20%20%20%20%20%20%3CBASICHTTPBINDING%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%3CBINDING%20name%3D%22BasicHttpsBinding_IService1%22%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSECURITY%20mode%3D%22Transport%22%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CTRANSPORT%20clientcredentialtype%3D%22Certificate%22%3E%3C%2FTRANSPORT%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FSECURITY%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%3C%2FBINDING%3E%0A%0A%20%20%20%20%20%20%20%20%3C%2FBASICHTTPBINDING%3E%0A%0A%20%20%20%20%20%20%3C%2FBINDINGS%3E%0A%0A%20%20%20%20%20%20%3CCLIENT%3E%0A%0A%20%20%20%20%20%20%20%20%3CENDPOINT%20address%3D%22https%3A%2F%2Fwcfclientcertsample.azurewebsites.net%2FService1.svc%22%20binding%3D%22basicHttpBinding%22%20bindingconfiguration%3D%22BasicHttpsBinding_IService1%22%20behaviorconfiguration%3D%22endpointCredentialBehavior%22%20contract%3D%22ServiceReference1.IService1%22%20name%3D%22BasicHttpsBinding_IService1%22%3E%3C%2FENDPOINT%3E%0A%0A%20%20%20%20%20%20%3C%2FCLIENT%3E%0A%0A%20%20%20%20%20%20%3CBEHAVIORS%3E%0A%0A%20%20%20%20%20%20%20%20%3CENDPOINTBEHAVIORS%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%3CBEHAVIOR%20name%3D%22endpointCredentialBehavior%22%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CCLIENTCREDENTIALS%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CCLIENTCERTIFICATE%20findvalue%3D%229c8a3857851e653ff22f0161914a1accf8ac5e76%22%20storelocation%3D%22CurrentUser%22%20storename%3D%22My%22%20x509findtype%3D%22FindByThumbprint%22%3E%3C%2FCLIENTCERTIFICATE%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FCLIENTCREDENTIALS%3E%0A%0A%20%20%20%20%20%20%20%20%20%20%3C%2FBEHAVIOR%3E%0A%0A%20%20%20%20%20%20%20%20%3C%2FENDPOINTBEHAVIORS%3E%0A%0A%20%20%20%20%20%20%3C%2FBEHAVIORS%3E%20%0A%0A%20%20%20%20%3C%2FSYSTEM.SERVICEMODEL%3E%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%20start%3D%226%22%3E%0A%3CLI%3EAs%20in%20the%20Service%20end%20I%20have%20used%20a%20custom%20client%20certificate%20validator%20and%20for%20testing%20purpose%20I%20am%20printing%20the%20subject%20name%20of%20the%20client%20certificate%20passed%20via%20the%20custom%20validator%20in%20the%20service%20end.%20Now%20when%20we%20run%20the%20client%20we%20see%20the%20below%20Console%20Output.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Meghali_4-1618610552161.jpeg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F273450i6B8835FFA51AAAF9%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Meghali_4-1618610552161.jpeg%22%20alt%3D%22Meghali_4-1618610552161.jpeg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Apr 16 2021 03:22 PM
Updated by: