Pregunta

Am trying to query an odata web.api hosted on IIS7. The site requires a client cert. How do I attach the certificate to the query? Using web.api 2, framework 4.5, mvc5

string certPath = @"E:\ClientCertificate.cer";

Uri uri = new Uri("https://server/odata/"); 
var container = new CourseService.Container(uri);
container.ClientCertificate = new X509Certificate(certPath);

The extension to the container class was achieved by reading this: http://bartwullems.blogspot.co.uk/2013/03/odata-attach-client-certificate-through.htm

¿Fue útil?

Solución

You could attach the certificate to request in SendRequest2 event yourself:

    context.SendingRequest2 += (sender, eventArgs) =>
        {
            // We can safely cast RequestMessage to HttpWebRequestMessage if this is not in batch.
            if (!eventArgs.IsBatchPart)
            {
                ((HttpWebRequestMessage)eventArgs.RequestMessage).HttpWebRequest.ClientCertificates.Add(theCertificate);
            }
        };
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top