Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.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# 使用SSL协商对Web Api进行http请求的UWP应用程序_C#_.net_Ssl_X509certificate_Uwp - Fatal编程技术网

C# 使用SSL协商对Web Api进行http请求的UWP应用程序

C# 使用SSL协商对Web Api进行http请求的UWP应用程序,c#,.net,ssl,x509certificate,uwp,C#,.net,Ssl,X509certificate,Uwp,我正在尝试通过证书协商将UWP应用程序连接到启用了Web Api SSL(在IIS中)的Web Api。如果禁用证书协商,则以下代码可以工作,请求也可以工作,但没有客户端证书到达附加到请求的Web Api。提到firefox在GET请求时协商证书,一切都按预期工作(服务器接收证书) private async void btn\u addCertificate\u单击(对象发送方,路由目标) { 尝试 { Windows.Web.Http.HttpResponseMessage响应=等待test

我正在尝试通过证书协商将UWP应用程序连接到启用了Web Api SSL(在IIS中)的Web Api。如果禁用证书协商,则以下代码可以工作,请求也可以工作,但没有客户端证书到达附加到请求的Web Api。提到firefox在GET请求时协商证书,一切都按预期工作(服务器接收证书)

private async void btn\u addCertificate\u单击(对象发送方,路由目标)
{
尝试
{
Windows.Web.Http.HttpResponseMessage响应=等待testCertConnect();
字符串responseBodyAsText;
System.Diagnostics.Debug.WriteLine(response.StatusCode+“”+response.ReasonPhrase+Environment.NewLine);
responseBodyAsText=wait response.Content.ReadAsStringAsync();
系统.诊断.调试.写入线(responseBodyAsText);
}
捕获(例外情况除外)
{
System.Diagnostics.Debug.WriteLine(例如ToString());
}
}
专用异步任务testCertConnect()
{
Windows.Web.Http.Filters.HttpBaseProtocolFilter=新建Windows.Web.Http.Filters.HttpBaseProtocolFilter();
filter.ClientCertificate=certList[this.certificatesListCB.SelectedIndex];
Windows.Web.Http.HttpClient HttpClient=新的Windows.Web.Http.HttpClient(过滤器);
httpClient.DefaultRequestHeaders.UserAgent.tryparsead(“Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586”);
httpClient.DefaultRequestHeaders.AcceptEncoding.tryparsead(“gzip,deflate”);
httpClient.DefaultRequestHeaders.Add(“Pragma”,“无缓存”);
返回wait-wait-httpClient.GetAsync(新Uri(“https://:44300/api/sites”);
}
applicationhost.config中的SSL配置

<access sslFlags="Ssl, SslNegotiateCert" />

在SSL协商处于活动状态时执行请求时出错

Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.ni.dll
WinRT information: An error occurred in the secure channel support

Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.ni.dll
WinRT information: An error occurred in the secure channel support

System.Runtime.InteropServices.COMException (0x80072F7D): The text associated with this error code could not be found.

An error occurred in the secure channel support

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at PwdManager.AddCertificate.<testCertConnect>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at PwdManager.AddCertificate.<btn_addCertificate_Click>d__3.MoveNext()
在mscorlib.ni.dll中引发异常:“System.Runtime.InteropServices.COMException”
WinRT信息:安全通道支持中发生错误
引发异常:mscorlib.ni.dll中的“System.Runtime.InteropServices.COMException”
WinRT信息:安全通道支持中发生错误
System.Runtime.InteropServices.COMException(0x80072F7D):找不到与此错误代码关联的文本。
安全通道支持中出现错误
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在PwdManager.AddCertificate.d_u6.MoveNext()上
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()中
在PwdManager.AddCertificate.d_u3.MoveNext()中

注意:SSL证书是CA证书签名的,并且各自的PKI加载到证书存储。

我面临同样的问题。你能解决吗?@LohithKorupolu没有。很抱歉耽搁了。我也面临同样的问题。你能解决吗?@LohithKorupolu没有。很抱歉耽搁了。
Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.ni.dll
WinRT information: An error occurred in the secure channel support

Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.ni.dll
WinRT information: An error occurred in the secure channel support

System.Runtime.InteropServices.COMException (0x80072F7D): The text associated with this error code could not be found.

An error occurred in the secure channel support

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at PwdManager.AddCertificate.<testCertConnect>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at PwdManager.AddCertificate.<btn_addCertificate_Click>d__3.MoveNext()