Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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# 用于通过TLS进行WebSocket安全的WCF ServiceHost配置_C#_.net_Wcf_Websocket_Servicehost - Fatal编程技术网

C# 用于通过TLS进行WebSocket安全的WCF ServiceHost配置

C# 用于通过TLS进行WebSocket安全的WCF ServiceHost配置,c#,.net,wcf,websocket,servicehost,C#,.net,Wcf,Websocket,Servicehost,我已使用ServiceHost创建了WebSocket服务器: using (ServiceHost host = new ServiceHost(typeof(WebSocketsServer), baseAddress)) { CustomBinding binding = new CustomBinding(); binding.Elements.Add(new ByteStreamMessageEncodingBindingElement()); HttpTran

我已使用ServiceHost创建了WebSocket服务器:

using (ServiceHost host = new ServiceHost(typeof(WebSocketsServer), baseAddress))
{
    CustomBinding binding = new CustomBinding();
    binding.Elements.Add(new ByteStreamMessageEncodingBindingElement());
    HttpTransportBindingElement transport = new HttpTransportBindingElement();
    transport.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
    transport.WebSocketSettings.CreateNotificationOnConnection = true;
    binding.Elements.Add(transport);

    host.AddServiceEndpoint(typeof(IWebSocketsServer), binding, "");

    host.Open();
}
它与我的JavaScript应用程序配合得很好。目前,我正在尝试添加对WebSocket安全的支持。我已将HttpTransportBindingElement更改为HttpsTransportBindingElement,将baseurl更改为https://并将JavaScript应用程序中的连接url更改为wss://

using (ServiceHost host = new ServiceHost(typeof(WebSocketsServer), baseAddress))
{
    CustomBinding binding = new CustomBinding();
    binding.Elements.Add(new ByteStreamMessageEncodingBindingElement());
    HttpsTransportBindingElement transport = new HttpsTransportBindingElement();
    transport.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
    transport.WebSocketSettings.CreateNotificationOnConnection = true;

    binding.Elements.Add(transport);


    host.AddServiceEndpoint(typeof(IWebSocketsServer), binding, "");


    host.Open();
}
我希望它能工作,应用程序启动时没有错误,但在使用JavaScript连接之后,我遇到了这个错误

WebSocket连接到'wss://localhost:5555/wsData'失败:建立连接时出错:net::ERR_connection_RESET


是否有使用WebSocket secure所需的其他ServiceHost设置?WebSocket是否在Microsoft的ServiceModel中实现了安全性?

我终于找到了解决方案。上面提到的代码适用于该场景,但我必须为主机配置证书并通过HTTPS运行客户端应用程序。这篇文章很有帮助

我终于找到了解决办法。上面提到的代码适用于该场景,但我必须为主机配置证书并通过HTTPS运行客户端应用程序。这篇文章很有帮助