title: WCF WF Service, Could not establish secure channel for SSL/TLS with authority
body: <p>I keep getting the same error when trying to access my WCF WF Service: "Could not establish secure channel for SSL/TLS with authority."</p>
  
  <p>I have tried a bunch of stackoverflow/google solutions but no luck so far.</p>
  
  <p>I've made a WCF WF Service that connects to a thirdparty that uses a certificate to verify. My Web.config looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  &lt;appSettings&gt;
    &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/&gt;
  &lt;/appSettings&gt;
  &lt;system.web&gt;
    &lt;compilation debug="true" strict="false" explicit="true" 
                              targetFramework="4.5.1"/&gt;
    &lt;httpRuntime targetFramework="4.5.1"/&gt;
  &lt;/system.web&gt;
  &lt;system.serviceModel&gt;
    &lt;bindings&gt;      
      &lt;basicHttpsBinding&gt;
        &lt;binding name="binding1"&gt;
          &lt;security mode="TransportWithMessageCredential"&gt;
            &lt;message clientCredentialType="Certificate" /&gt;
          &lt;/security&gt;
        &lt;/binding&gt;
      &lt;/basicHttpsBinding&gt;
    &lt;/bindings&gt;
    &lt;client&gt;
      &lt;!-- Test Endpoint --&gt;
      &lt;endpoint address="https://example.com" 
                behaviorConfiguration="endpointBehavior" 
                binding="basicHttpsBinding" 
                bindingConfiguration="binding1" 
                contract="ContractPortType" 
                name="Port"&gt;
      &lt;/endpoint&gt;
    &lt;/client&gt;
    &lt;behaviors&gt;
      &lt;serviceBehaviors&gt;
        &lt;behavior&gt;
          &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
          &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;        
        &lt;/behavior&gt;
      &lt;/serviceBehaviors&gt;
      &lt;endpointBehaviors&gt;
        &lt;behavior name="endpointBehavior"&gt;
          &lt;clientCredentials&gt;          
            &lt;clientCertificate findValue="SOMETHUMBPRINT" 
                                storeLocation="LocalMachine" 
                                storeName="My" 
                                x509FindType="FindByThumbprint" /&gt;
          &lt;/clientCredentials&gt;
        &lt;/behavior&gt;
      &lt;/endpointBehaviors&gt;
    &lt;/behaviors&gt;
    &lt;protocolMapping&gt;
      &lt;add binding="basicHttpsBinding" scheme="https"/&gt;
    &lt;/protocolMapping&gt;
    &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
                               multipleSiteBindingsEnabled="true" 
                               minFreeMemoryPercentageToActivateService="1"/&gt;
  &lt;/system.serviceModel&gt;
  &lt;system.webServer&gt;
    &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p></p>
  
  <p>The client is just a simple console running this:</p>
  
  <pre><code>using (var client = new ServiceClient())
  {
       System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
       var msg = client.GetData();
       Console.WriteLine(msg);
   }
  </code></pre>
  
  <p>That has the following App.config:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /&gt;
    &lt;/startup&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;     
        &lt;basicHttpBinding&gt;
          &lt;binding name="BasicHttpBinding_IService"/&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  
      &lt;client&gt;
        &lt;endpoint address="http://localhost:55670/GetData.xamlx"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
          contract="Reference.IService" name="BasicHttpBinding_IService" behaviorConfiguration="endpointBehavior" /&gt;
      &lt;/client&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="endpointBehavior"&gt;
            &lt;clientCredentials&gt;
              &lt;clientCertificate findValue="SOMETHUMBPRINT"
                                 storeLocation="LocalMachine"
                                 storeName="My"
                                 x509FindType="FindByThumbprint" /&gt;
            &lt;/clientCredentials&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>It would be great if somebody could help me out.</p>
  
  <p>EDIT:
  So the thing that I can't seem to get working is the SSL connection needed between my WCF WF serivce and the thirdparty service. When I directly call the thirdparty service from a client then I can set the System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  but I can't find a way to do the same for my WCF WF service.</p>
  
  <p>EDIT:
  So I can make it work by creating an activity and then calling that activity before I call the thirdparty activity and then it works, but there has to be a better way! </p>
  
  <pre><code>public sealed class SetTlsVersion : CodeActivity
  {
      protected override void Execute(CodeActivityContext context)
      {
          System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
      }
  }
  </code></pre>