title: Problems authenticating .net C# client on Java Webservice via https and certificate
body: <p>I am implementing a c# webservice client that has to consume a Java webservice. Communication protocol is https and authentication has to be done via certificate (including private key).</p>
  
  <p>As far as I know the purpose of the private key is to identify the correct customer database behind the webservice. </p>
  
  <p>I don´t know the format of the certificate file because its file extension is "txt". If I try to import this file in the windows certificate store via mmc console an error occurs "file type could not be recognized" (I translated this from german, so it may sound a little bit different in english). So my client app can not use this certificate it would not find it in the certificate store.</p>
  
  <p>I tried to instantiate the certificate and passing the file location into the constructor.</p>
  
  <pre><code> mVerifyCert = new X509Certificate2(AppConfig.Settings.Default.CertificateAndKeyFileFullName);
  </code></pre>
  
  <p>But then the following exception occurs (in english it might be "System.Security.Cryptography.CryptographicException: Object was not found."</p>
  
  <p>{System.Security.Cryptography.CryptographicException: Das angeforderte Objekt wurde nicht gefunden.</p>
  
  <p>bei System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
     bei System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName)
     bei System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)
     bei System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName)
     bei System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName)</p>
  
  <p>So now one might think there would be a problem with the file. But when this file is used with SoapUI Tool to test the webservice it works fine.
  I also hava java example client app the uses this file with java trust store and it works fine for the java client.</p>
  
  <p>I have also tried to change the file extension from "txt" to "p12", "pem" in order to be able to import the file into windows certificate store but no success.</p>
  
  <p>Can you tell me whats the problem here? What can I do to solve this. I have no clue at all.</p>
  
  <p>Here is my app.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
              &lt;section name="QcsiSync.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
      &lt;userSettings&gt;
          &lt;QcsiSync.Properties.Settings&gt;
              &lt;setting name="DefactInstanceXmlFileNameFull" serializeAs="String"&gt;
                  &lt;value&gt;..\..\Data\getDefactInstance.xml&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="DefactInstanceXmlDotNet" serializeAs="String"&gt;
                  &lt;value&gt;..\..\Data\DefactInstanceXmlDotNet.xml&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="WebServiceUrl" serializeAs="String"&gt;
                  &lt;value&gt;https://xyz.com/wsAdapter&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="CertificateFileFullName" serializeAs="String"&gt;
                  &lt;value&gt;..\..\Data\sdm.crt&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="CertificateAndKeyFileFullName" serializeAs="String"&gt;
                  &lt;value&gt;..\..\Data\sdmCert + key.txt&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="QcSupplierUrl" serializeAs="String"&gt;
                  &lt;value&gt;https://xyz.net/qcbin&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="QcSupplierUsername" serializeAs="String"&gt;
                  &lt;value&gt;xyz&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="QcSupplierPassword" serializeAs="String"&gt;
                  &lt;value&gt;xyz&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="QcSupplierDomain" serializeAs="String"&gt;
                  &lt;value&gt;xyz&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="QcSupplierProjetName" serializeAs="String"&gt;
                  &lt;value&gt;xyz&lt;/value&gt;
              &lt;/setting&gt;
          &lt;/QcsiSync.Properties.Settings&gt;
      &lt;/userSettings&gt;
      &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;basicHttpBinding&gt;
                  &lt;binding name="WSAdapterBFPortBinding" 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="Mtom" textEncoding="utf-8" transferMode="Buffered"
                      useDefaultWebProxy="true"&gt;
                      &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                          maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
                      &lt;security mode="None"&gt;
                          &lt;transport clientCredentialType="None" proxyCredentialType="None"
                              realm="" /&gt;
                          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;
                  &lt;binding name="WSAdapterBFPortBinding1" 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="Mtom" 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="UserName" algorithmSuite="Default" /&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;
                  &lt;!--&lt;binding name="WSAdapterBFPortBinding2" 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="Mtom" textEncoding="utf-8" transferMode="Buffered"
                      useDefaultWebProxy="true"&gt;
                      &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                          maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
                      &lt;security mode="None"&gt;
                          &lt;transport clientCredentialType="None" proxyCredentialType="None"
                              realm="" /&gt;
                          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;--&gt;
              &lt;/basicHttpBinding&gt;
          &lt;/bindings&gt;
          &lt;client&gt;
              &lt;endpoint address="http://localhost:8890/wsAdapter" binding="basicHttpBinding"
                  bindingConfiguration="WSAdapterBFPortBinding" contract="QcsiWS.WSAdapterBCI"
                  name="WSAdapterBFPortHttp" /&gt;
              &lt;endpoint address="https://xyz.com/wsAdapter"
                  binding="basicHttpBinding" bindingConfiguration="WSAdapterBFPortBinding1"
                  contract="QcsiWebService.WSAdapterBCI" name="WSAdapterBFPortHttps" /&gt;
          &lt;/client&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration
  </code></pre>