Alois
Alois

Reputation: 93

How can I read the Clientcertificate within a WCF service?

I do host a WCF service on a server which requires the clients to authenticate using a x509 certificate. I need to read this certificate inside the service as the data contained is part of the business logic.

The binding I use for the WCF service is webHttpBinding with security set to "Transport" and clientCredentialType="certificate".

In ASP.net I can use the HttpContext.Current, which however is not available in WCF. What can I do to still get the certificate from the user?

Kind regards, Alois

Upvotes: 3

Views: 1788

Answers (2)

Peter Hedberg
Peter Hedberg

Reputation: 3649

I use this in my WCF service, with ASP.net compatibility disabled:

var x509ClaimSet = OperationContext.Current.ServiceSecurityContext.AuthorizationContext.ClaimSets.FirstOrDefault() as X509CertificateClaimSet;

Upvotes: 1

Alois
Alois

Reputation: 93

The article on http://blogs.msdn.com/b/wenlong/archive/2006/01/23/516041.aspx provided me with the solution to this problem. WCF allows to run in "ASP.net compatibility mode" which brings back the full HttpContext object.

Upvotes: 1

Related Questions