1. Creation of certificates
MAKECERT.EXE-SR localmachine-ss my-a sha1-n Cn=parkingserver-sky Exchange-
Note: After the certificate is finished, the corresponding certificate Read permission is also configured.
WCF takes the certificates of the certificate, and the server and client are modified accordingly.
2. Modification of the service side
Behavior node:
<Behaviorname= "Custombehavior"> <Servicemetadatahttpgetenabled= "true" /> <ServicedebugIncludeexceptiondetailinfaults= "true" /> <ServiceCredentials> <ClientCertificate> <AuthenticationCertificatevalidationmode= "None" /> </ClientCertificate> <servicecertificatefindvalue= "Parkingserver"storelocation= "LocalMachine"StoreName= "My"X509FindType= "Findbysubjectname" /> </ServiceCredentials> </Behavior>
Binding node
<Wshttpbinding> <bindingname= "Customwshttpbinding"> <SecurityMode= "Message"> <messageclientCredentialType= "Certificate"/> </Security> </binding> </Wshttpbinding>
Service node
<Servicename= "Wcfservice1.service1"behaviorconfiguration= "Custombehavior"> <EndpointAddress=""binding= "Wshttpbinding"bindingconfiguration= "Customwshttpbinding"Contract= "Wcfservice1.iservice1"> <Identity> <DNSvalue= "Parkingserver" /> </Identity> </Endpoint> <EndpointAddress= "Mex"binding= "mexHttpBinding"Contract= "IMetadataExchange" /> </Service>
3. Client-side modifications
Client-endpoint node
<EndpointAddress= "Http://localhost:60909/Service2.svc"binding= "BasicHttpBinding"behaviorconfiguration= "CustomBehavior2"bindingconfiguration= "Basichttpbinding_iservice2"Contract= "Servicereference2.iservice2"name= "Basichttpbinding_iservice2"> <Identity> <DNSvalue= "Parkingserver" /> </Identity> </Endpoint>
Bindings node
<BasicHttpBinding> <bindingname= "Basichttpbinding_iservice2"> <SecurityMode= "Message"> <messageclientCredentialType= "Certificate" /> </Security> </binding> </BasicHttpBinding>
Behavior node
Behavior nodes, wshttpbindings and basichttpbindings have different binding content. Basichttpbindings more than one defaultcertificate configuration
Basichttpbindings
<Behaviorname= "CustomBehavior2"> <ClientCredentials> <ClientCertificatefindvalue= "Zoesoft"X509FindType= "Findbysubjectname"storelocation= "LocalMachine"StoreName= "My"/> <servicecertificate> <AuthenticationCertificatevalidationmode= "None"/> <defaultcertificatefindvalue= "Parkingserver"StoreName= "My"storelocation= "LocalMachine"X509FindType= "Findbysubjectname"/> </servicecertificate> </ClientCredentials> </Behavior>
Wshttpbindings
<Behaviorname= "Custombehavior"> <ClientCredentials> <ClientCertificatefindvalue= "Zoesoft"X509FindType= "Findbysubjectname"storelocation= "LocalMachine"StoreName= "My"/> <servicecertificate> <AuthenticationCertificatevalidationmode= "None"/> </servicecertificate> </ClientCredentials> </Behavior>
Reference:
WCF Development Framework formation journey--How to implement X509 certificate encryption
Invoke WCF service from Java clients with authentication (CERTIFICATE) Java client calls WCF services requires secure authentication
WCF + + Validation