The service certificate is not provided for target

2019-07-20 20:15发布

问题:

I have implemented a test Client / Server that implements UserName message authentication over WCF. It almost all works however I have fallen at the last hurdle.

I get an InvalidOperationException that reads

The service certificate is not provided for target 'http://localhost:8732/Design_Time_Addresses/EvalServiceLibrary/Service1/'. Specify a service certificate in ClientCredentials.

Can anyone shed any light?

Thanks

回答1:

Sounds like your requiring a certificate for security and your client code is not supplying the certificate on request. WCF Security



回答2:

Include something like this in your client configuration file:

<client>
 <endpoint address="http://example.com/Myservice.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
        contract="Core.IService" name="WSHttpBinding_IService" behaviorConfiguration="myServiceBehaviour" >
   <identity>
    <dns value="SampleServiceCertificate"/>
   </identity>
 </endpoint>
</client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="myServiceBehaviour">
          <clientCredentials>
            <serviceCertificate>
              <defaultCertificate storeLocation="LocalMachine" storeName="My" findValue="SampleServiceCertificate" x509FindType="FindBySubjectName"  />
            </serviceCertificate>
          </clientCredentials>
        </behavior>            
      </endpointBehaviors>          
    </behaviors>


回答3:

Your client needs to be able to authenticate the service by reference to an X509certificate, the public key of which it will use to encrypt messages sent to the service.

The service certificate is identified on the client side by the ServiceCertificate property of the ClientCredentials. The error message is telling you that your configuration/code hasn't set this up correctly. If you post your code/config we may be able to tell you what's wrong.



标签: c# wcf ssl