c# - attach a client certificate through code when connecting to an OData service -
am trying query odata web.api hosted on iis7. site requires client cert. how attach certificate 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 container class achieved reading this: http://bartwullems.blogspot.co.uk/2013/03/odata-attach-client-certificate-through.htm
you attach certificate request in sendrequest2 event yourself:
context.sendingrequest2 += (sender, eventargs) => { // can safely cast requestmessage httpwebrequestmessage if not in batch. if (!eventargs.isbatchpart) { ((httpwebrequestmessage)eventargs.requestmessage).httpwebrequest.clientcertificates.add(thecertificate); } };
Comments
Post a Comment