【问题标题】:Can I connect to local windows service application with secure WebSocket (wss)我可以使用安全 WebSocket (wss) 连接到本地 Windows 服务应用程序吗
【发布时间】:2021-01-20 02:41:34
【问题描述】:

我可以使用安全 WebSocket (wss) 连接到本地 Windows 服务应用程序 (c#)

https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

要连接的 URL;这应该是 WebSocket 服务器将响应的 URL。这应该使用 URL 方案 wss://,虽然某些软件可能允许您使用不安全的 ws:// 进行本地连接。

【问题讨论】:

  • Can I connect to local windows service application (c#) with secure WebSocket (wss) - 可以,只要您的本地 Windows 服务应用程序配置为这样做
  • 我在尝试 wss 时遇到错误,我的新帖子是 stackoverflow.com/questions/64220221/…

标签: javascript c# windows websocket service


【解决方案1】:

我解决了

X509Certificate oCertificate = CertificateKontrol.GetCertificate();

 public class CertificateKontrol
    {
        public static X509Certificate2 GetCertificate()
        {
            try
            {                        
                byte[] barySertifika = global::EImzaAt.Properties.Resources.cert;
                using (Stream stream = new MemoryStream(barySertifika))
                {
                    return new X509Certificate2(ReadStream(stream), pwd);
                }
            }
            catch (System.Exception ex)
            {
                throw new System.Exception("err");
            }
        }

        private static byte[] ReadStream(Stream input)
        {
            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }
    }

【讨论】:

    猜你喜欢
    • 2018-03-24
    • 2021-06-23
    • 2020-03-04
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 2022-11-14
    相关资源
    最近更新 更多