简体   繁体   中英

Why I can't find the certificate in a WCF Service?

I'm trying to develop a service with WCF but I can't find the certificate that I created, this certificate is located under TrustedPeple folder. So far this is my chunk of code that I wrote:

client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
            StoreLocation.CurrentUser,
            StoreName.My,
            X509FindType.FindBySubjectName,
            "WCfClient");

As you can see from the above code, I also tried to manually set the certificate characteristics but I still can't find it.

Also I'll post a portion of my conif xml file for a better understanding:

<services>

      <service 
        name="XMLServices.CriDecServices.CriDecService"
        behaviorConfiguration="wsHttpCertificateBehavior">
        <endpoint name="CriDecPoint"
          address=""
          binding="wsHttpBinding"
          bindingConfiguration="wsHttpEndpointBinding"
          contract="XMLContracts.ServiceContracts.ICriDecService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/XMLServices/CriDecServices/CriDecService" />
          </baseAddresses>
        </host>
        </service>


      <service
        name="XMLServices.UtenteServices.UtenteService"
        behaviorConfiguration="wsHttpCertificateBehavior">
        <endpoint
          name="UserPoint"
          address="" 
          binding="wsHttpBinding"
          bindingConfiguration="wsHttpEndpointBinding"
          contract="XMLContracts.ServiceContracts.IUtenteService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8766/XMLServices/UtenteServices/UtenteService" />
          </baseAddresses>
        </host>
      </service>
      </services>

This is the exception that I get:

"Client certificate not given. Specify a client certificate in ClientCredentials."

Can anyone help me out to understand why I can't seem to find my certificate? Thanks

If you look here you'll see that the store you are trying to use isn't the one from the trusted people folder but the one from the personal folder

you should use

StoreName.TrustedPeople

look here for more details https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename(v=vs.110).asp

also most likely you need StoreLocation.LocalMachine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM