title: could not establish secure channel for ssl/tls with authority wcf C# wcf rest service
body: <p>I create a client application that get data from my rest wcf service as you can see :</p>
  
  <pre><code> Uri reqUri = new Uri("https://localhost/paymentservice.svc/listpayment");
  
  
  
              WebRequest req = WebRequest.Create(reqUri);
  
              req.PreAuthenticate = true;
  
              NetworkCredential credential = new NetworkCredential("test", "test123");
  
              req.Credentials = credential;
  
              WebResponse resp = req.GetResponse();
  
  
              DataContractSerializer data = new DataContractSerializer(typeof(string));
              var res = data.ReadObject(resp.GetResponseStream());
  
              Console.WriteLine(res);
  
              Console.ReadLine();
  </code></pre>
  
  <p>I create a certificate in iis as you can se :</p>
  
  <p><a href="https://i.stack.imgur.com/VqSVO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VqSVO.png" alt="enter image description here"></a></p>
  
  <p>And upload my published file on it .
  But when i call my client i get this error :</p>
  
  <pre><code>An unhandled exception of type 'System.Net.WebException' occurred in System.dll
  
  Additional information: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel
  </code></pre>
  
  <p>Here is my service webconfig</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;appSettings&gt;
      &lt;add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.5.2" /&gt;
      &lt;httpRuntime targetFramework="4.5.2" /&gt;
      &lt;httpModules&gt;
        &lt;add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" /&gt;
      &lt;/httpModules&gt;
      &lt;authentication mode="None" /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="secureHttpBinding"&gt;
            &lt;security mode="Message"&gt;
              &lt;message clientCredentialType="UserName" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
        &lt;service name="Payment.Application.ServiceImplement.PaymentService" behaviorConfiguration="customBehaviour"&gt;
          &lt;endpoint address=""
                    binding="webHttpBinding"
                    contract="Payment.Domain.Service.IPaymentService"
                    behaviorConfiguration="web"/&gt;
  
        &lt;/service&gt;
        &lt;service name="Payment.Infrustructure.RepositoryImplement.PaymentRepository" behaviorConfiguration="customBehaviour" &gt;
          &lt;endpoint address=""
                    binding="webHttpBinding"
                    contract="Payment.Domain.Repository.IPaymentRepository"
                    behaviorConfiguration="web"/&gt;
        &lt;/service&gt;
  
      &lt;/services&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior  name="customBehaviour"&gt;
            &lt;serviceCredentials&gt;
              &lt;userNameAuthentication userNamePasswordValidationMode="Custom"
                                      customUserNamePasswordValidatorType="Payment.Service.UserAuthentication,Payment.Service"/&gt;
            &lt;/serviceCredentials&gt;
  
            &lt;!-- To avoid disclosing metadata information, set the values below to false before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /&gt;
            &lt;!-- 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 --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
        &lt;endpointBehaviors&gt;
  
          &lt;behavior name="web"&gt;
            &lt;webHttp/&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" /&gt;
    &lt;/system.serviceModel&gt;
  
    &lt;system.webServer&gt;
      &lt;httpProtocol&gt;
        &lt;customHeaders&gt;
          &lt;add name="Access-Control-Allow-Methods" value="GET, POST,PUT,DELETE" /&gt;
        &lt;/customHeaders&gt;
      &lt;/httpProtocol&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"&gt;
        &lt;remove name="ApplicationInsightsWebTracking" /&gt;
        &lt;add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" /&gt;
      &lt;/modules&gt;
      &lt;!--
          To browse web app root directory during debugging, set the value below to true.
          Set to false before deployment to avoid disclosing web app folder information.
        --&gt;
      &lt;directoryBrowse enabled="true" /&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
    &lt;/system.webServer&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;connectionStrings&gt;
      &lt;add name="DefaultConnection" connectionString="Data Source=.;initial catalog=SymfaDB;user id= sa ;password=12345;" providerName="System.Data.SqlClient" /&gt;
      &lt;!--&lt;add name="DefaultConnection" connectionString="Data Source=92.50.12.222,1433;initial catalog=ParkingDB;user id= sa ;password=123qweQWE@;" providerName="System.Data.SqlClient" /&gt;--&gt;
    &lt;/connectionStrings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>When irun the project in visual studio and call this url <code>http://localhost:4428/PaymentService.svc/listpayment</code> I get the data as you can see :
  <a href="https://i.stack.imgur.com/beO92.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/beO92.png" alt="enter image description here"></a></p>
  
  <p>But when i upload the publish file into iis and call this url <code>https://localhost/PaymentService.svc/listpayment</code> as you can see i get this error :</p>
  
  <p><a href="https://i.stack.imgur.com/53MFP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/53MFP.png" alt="enter image description here"></a></p>
  
  <p>As you can see when i call this <code>https://localhost/PaymentService.svc</code> my service is available .
  <a href="https://i.stack.imgur.com/Q1Rsr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q1Rsr.png" alt="enter image description here"></a></p>