我试图查询IIS7上托管的odata web.api。该站点需要客户端证书。如何将证书附加到查询?使用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);
通过阅读以下内容实现了容器类的扩展: http://bartwullems.blogspot.co.uk/2013/03/odata-attach-client-certificate-through.htm
答案 0 :(得分:0)
您可以自己附加证书以在SendRequest2事件中请求:
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);
}
};