Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 连接到OData服务时通过代码附加客户端证书_C#_Ssl_Client_Ssl Certificate_Odata - Fatal编程技术网

C# 连接到OData服务时通过代码附加客户端证书

C# 连接到OData服务时通过代码附加客户端证书,c#,ssl,client,ssl-certificate,odata,C#,Ssl,Client,Ssl Certificate,Odata,我正在尝试查询IIS7上托管的odata web.api。该站点需要客户端证书。如何将证书附加到查询?使用web.api 2、框架4.5、mvc5 string certPath = @"E:\ClientCertificate.cer"; Uri uri = new Uri("https://server/odata/"); var container = new CourseService.Container(uri); container.ClientCertificate = new

我正在尝试查询IIS7上托管的odata web.api。该站点需要客户端证书。如何将证书附加到查询?使用web.api 2、框架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);
容器类的扩展是通过阅读以下内容实现的:

您可以自己在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);
            }
        };

在调试中,容器的客户端证书为空,它似乎没有附加…Hamlet,谢谢编辑。。。