title: Issues connecting to a web service in C#
body: <p>I am using a third party wsdl to connect to a service. I have been provided a security certificate and a username / password.</p>
  
  <p>I have:</p>
  
  <ul>
  <li>Installed the certificate on my Windows 7 machine</li>
  <li>Ensured it has the correct permissions</li>
  <li>Have the correct location for the API stored in the web.config</li>
  </ul>
  
  <p>The code fails each time. The error messages change, but they include:</p>
  
  <ul>
  <li>Authentication failed because the remote party has closed the transport stream.</li>
  <li>An existing connection was forcibly closed by the remote host</li>
  <li>Could not create SSL/TLS secure channel</li>
  </ul>
  
  <p>This is the code I am executing:</p>
  
  <pre><code>ServicePointManager.Expect100Continue = true;
  ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
  
  //Third party client
  var client = new ConnectionPortClient();
  
  //Including these two lines or not does not affect the outcome
  //client.ClientCredentials.UserName.UserName = "username";
  //client.ClientCredentials.UserName.Password = "password";
  
  client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(@"C:\..\cert.p12", "password", X509KeyStorageFlags.MachineKeySet);
  
  var results = client.getResults("");
  </code></pre>
  
  <p>And here is the relevant part of the web.config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="assessmentBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
              receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
              bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
              messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
              useDefaultWebProxy="true"&gt;
            &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
            &lt;security mode="Transport"&gt;
              &lt;transport clientCredentialType="None" proxyCredentialType="None"
                  realm="" /&gt;
              &lt;message clientCredentialType="Certificate" algorithmSuite="Default" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="https://endpoint/" binding="basicHttpBinding"
            bindingConfiguration="assessmentBinding" contract="API.Assessment"
            name="assessmentSOAP" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>Any thoughts on what's going on here?</p>