Add WCF Service Reference to Visual Studio 2022 Project with Client Certificate

Viewed 258

I am attempting to add a WCF Web Service reference to a C# project where the WSDL is secured behind a client certificate. I have successfully added the certificate to SOAPUI and made calls just fine, but when I attempt to add the reference in Visual Studio, I dont get prompted to select the certificate.

How do I add a WCF Service endpoint which requires a client certificate in Visual Studio 2022 Community?

1 Answers

Specify the client certificate using endpoint behavior like below:

<system.serviceModel>  
<behaviors>  
  <endpointBehaviors>  
    <behavior name="endpointCredentialsBehavior">  
      <clientCredentials>  
        <clientCertificate findValue="Cohowinery.com"
           storeLocation="LocalMachine"  
          x509FindType="FindBySubjectName" />  
      </clientCredentials>  
    </behavior>  
  </endpointBehaviors>  
</behaviors>
<bindings>  
  <wsHttpBinding>  
    <binding name="WSHttpBinding_ICalculator" >  
      <security mode="Message">  
        <message clientCredentialType="Certificate" />  
      </security>  
    </binding>  
  </wsHttpBinding>  
</bindings>  
<client>  
  <endpoint address="http://machineName/Calculator"
            behaviorConfiguration="endpointCredentialsBehavior"  
            binding="wsHttpBinding"  
            bindingConfiguration="WSHttpBinding_ICalculator"  
            contract="ICalculator"  
            name="WSHttpBinding_ICalculator">   
  </endpoint>  
</client> 

For more information, check out Message Security with a Certificate Client or Transport Security with Certificate Authentication.

Related