出坑记录C#.net2.0 win server2008 R2 sp1 react前端连接websocket无法连接

14 篇文章 0 订阅

无法连接的解决办法:

1.

把下面设置存成reg文件导入

Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello\Client]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0\Client]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Client]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2]
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
 
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000

2.下载kb3154518的补丁安装,

这个安装包比较坑,中文的连接中是下载不到的,而且在www.catalog.update.microsoft.com上也没找到这个3154518的更新...

此连接下载不了的原因是因为连接是机器翻译的英文的,包括url,正文内容都翻译了,下载url就失效了,从英文的页面中就可以下载了.

http://download.microsoft.com/download/6/8/0/680ee424-358c-4fdf-a0de-b45dee07b711/windows6.1-kb3154518-x64.msu

上面连接可以下载x64的的,对应的x86的是:

http://download.microsoft.com/download/6/8/0/680ee424-358c-4fdf-a0de-b45dee07b711/windows6.1-kb3154518-x86.msu

3.服务器的代码还是保持.net2.0,但是在代码中,要强制转换一下tsl1.2的支持了

最后一行代码必须注释,如果设置为none,微信小程序连接不上.

上面第4行代码中,4080是支持全部模式,3072是只使用tsl1.2,或者使用下面的代码模式,或者自己扩展一个.net的扩展类自己重写枚举

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                       | SecurityProtocolType.Tls
                                       | (SecurityProtocolType)0x300 //Tls11
                                       | (SecurityProtocolType)0xC00; //Tls12

第一行代码中,证书最好不要用自签名证书,我之前用自签名证书微信小程序ios真机无法连接,但是那时候我没用上面代码的倒数第三行.反正域名也是有的,证书也有买的,就不用自签名的了.

4.参考文章

使用PowerShell设置:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3 -bor [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

设置后查看:

[Net.ServicePointManager]::SecurityProtocol


 

过程中发生的错误有:


VM244:1 WebSocket connection to 'wss://www.xxx.xxx:33333/xxxxx' failed:   后面啥也没有了 不显示失败原因,try catch也捕获不到.(这原因可能就很多了,比如本文说的不支持tsl1.2的问题)


VS2013调试发生错误:对SSPI的调用失败,请参阅内部异常,是在调用SSLStream.AuthenticateAsServer中出现的问题 英文资料搜( fails with "A call to SSPI failed, see inner exception.")

在vs输出窗口输出system.security.authentication.authenticationexception 类型的第一次机会异常,一开始这个异常没有捕获到,后来在vs中  调试->异常->

把这个勾选上就能捕获到了,关于 调试,选项,符号,那里不需要打钩的.调试->选项->常规里面的也不需要动.


前端出现1006错误,reason也是"" 直接就是空的没说任何理由.没连接直接就断开了,服务端没有收到请求(至少在onmessage,onerror,onopen,onclose事件中都没有监听到客户端的连接,具体没有通过wireshark之类的测试过)


其中设想过各种原因:


https中连接ws不允许,http中连接wss不允许? 

并不是,实际上只要websocket连接没有问题,在http中(我的是yarn start)启动的本地前端调试,后来也可以连接wss服务器

不过,之前在wss不能连接的时候,的确ws在http调试页面下连接成功了.只是因为没有授权校验过程所以连上就容易了.


ssl整数等级问题导致不能连接wss?

并不是


浏览器直接拦截了请求或者js中的websocket代码本身的问题?

并不是


new websocket的第二个参数protocols,没有使用SOAP/XAMP的参数问题?

并不是,不需要指定第二个参数,直接就一个参数初始化websocket就好,除了soap/xamp之外的填写什么ws    wss  tls 之类的都是错误的.


websocket-sharp本身代码缺陷问题?

并不是


会不会是wss连接不能配置端口,只能使用443,然后想要用别的端口需要用什么iis的反向代理之类的?

并不是,wss连接支持指定端口,也不需要iis反向代理.并不是像其他网友说的iis用了443,其他的websocket服务就必须通过iis转发到websocket服务.也不是像微信开发者社区中有人说的wss连接必须443端口.


没有为端口配置tls1.2?

并不是,证书是基于域名的,跟端口没有关系,在初始化websocket服务器的时候指定证书就行了,至于端口是多少,只是连接的时候端口号不一样而已.


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Afterwards_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值