vb.net SignalR - WebSocket 错误:网络错误 12030,与服务器的连接异常终止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28764198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SignalR - WebSocket Error: Network Error 12030, The connection with the server was terminated abnormally
提问by Kevin Hornsby
Trying to get SignalR working on the webserver(IIS 8, Server 2012, websockets installed, .NET 4.5) but having no joy.
试图让 SignalR 在网络服务器(IIS 8,Server 2012,安装的 websockets,.NET 4.5)上工作,但没有乐趣。
Works great on my local IIS(windows 8 and connects with websockets)
在我的本地 IIS 上运行良好(Windows 8 并与 websockets 连接)
<httpRuntime targetFramework="4.5"/>
and
和
<compilation strict="false" explicit="true" targetFramework="4.5" debug="false">
Set in webconfig
在 webconfig 中设置
Local signalr logging:
本地信号器记录:
[11:26:17 GMT+0000 (GMT Standard Time)] SignalR: Client subscribed to hub 'notificationhub'.
[11:26:17 GMT+0000 (GMT Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D'.
[11:26:17 GMT+0000 (GMT Standard Time)] SignalR: webSockets transport starting.
[11:26:17 GMT+0000 (GMT Standard Time)] SignalR: Connecting to websocket endpoint 'ws://localhost:22038/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=W5PmClxV6R32xJpuP5It2NUDVvJXOESGJCrgQYb67z59ODUJFr13zQzgBgTYEfmr4XbgMmRGU3ZncQS3yZU2Hmh%2Fc3h%2F17fh9gRlUOUdnaVYcnls%2BQon%2F7R0ckNw8MnLcrG1pg%3D%3D&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D&tid=3'.
[11:26:17 GMT+0000 (GMT Standard Time)] SignalR: Websocket opened.
[11:26:17 GMT+0000 (GMT Standard Time)] SignalR: webSockets transport connected. Initiating start request.
[11:26:18 GMT+0000 (GMT Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state.
[11:26:18 GMT+0000 (GMT Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
hub start, connection id=01b7a623-5531-496c-a5e1-ab0876e2c1a6
Server log:
服务器日志:
[11:24:01 GMT+0000 (GMT Standard Time)] SignalR: Client subscribed to hub 'notificationhub'.
[11:24:01 GMT+0000 (GMT Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D'.
[11:24:02 GMT+0000 (GMT Standard Time)] SignalR: webSockets transport starting.
[11:24:02 GMT+0000 (GMT Standard Time)] SignalR: Connecting to websocket endpoint 'ws://foo.co.uk/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=uibfnMomSreytNZY7UiusFWoTjNWO6%2FNIaBzIM%2FVVSBOXk6SNlyULUH%2FaGWoPynoEbx6sKRfShJG0zrd846uqgdgEK6xQIP2K5j3xfwtBlngGG3i6k%2FYoHNk5subReA3TsCxfw%3D%3D&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D&tid=10'.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: Websocket opened.
SCRIPT12030: WebSocket Error: Network Error 12030, The connection with the server was terminated abnormally
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: Unclean disconnect from websocket: [no reason given].
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: Closing the Websocket.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: webSockets transport failed to connect. Attempting to fall back.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: serverSentEvents transport starting.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: This browser doesn't support SSE.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: serverSentEvents transport failed to connect. Attempting to fall back.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: foreverFrame transport starting.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: Binding to iframe's load event.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: Iframe transport started.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: foreverFrame transport connected. Initiating start request.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state.
[11:24:03 GMT+0000 (GMT Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
hub start, connection id=cd2af7f4-5f85-40bb-a0a6-f8f8060bedae
Even though it appears to be connected using foreverFrame it does not fire the appropriate hub responses.
即使它看起来是使用foreverFrame 连接的,它也不会触发适当的集线器响应。
回答by Simon_Weaver
Nondescript errors like this can occur if there are JSON serialization problems on the server. I would expect a proper exception for most normal exceptions.
如果服务器上存在 JSON 序列化问题,则可能会出现此类非描述性错误。对于大多数正常异常,我希望有一个适当的异常。
In my case I made a really stupid mistake and had TWO properties with the same JsonProperty name in my return message (server side). Basically a cut and paste error that took a while to be noticed because 'SuggestedCities' wan't always populated.
在我的情况下,我犯了一个非常愚蠢的错误,并且在我的返回消息(服务器端)中有两个具有相同 JsonProperty 名称的属性。基本上是一个剪切和粘贴错误,需要一段时间才能注意到,因为 'SuggestedCities' 并不总是填充。
public class ValidateZipStateResponse
{
[JsonProperty("correctedCity")]
public string CorrectedCity { get; set; }
[JsonProperty("correctedState")]
public string CorrectedState { get; set; }
[JsonProperty("correctedState")]
public string[] SuggestedCities { get; set; }
}
Make sure client side you enable debugging. It won't help with this error, but in general it's quite useful and you'll see a useful log in the browser console.
确保客户端启用调试。它不会帮助解决此错误,但总的来说它非常有用,您会在浏览器控制台中看到有用的日志。
$.connection.hub.logging = true;
回答by Kevin Hornsby
After trying the website on my home connection I found it connected to websockets fine.
在我的家庭连接上尝试该网站后,我发现它可以很好地连接到 websockets。
So I am going to assume there is some kind of Proxy server inbetween my "work" pc and the web server. Of which I have no access to. (Assuming Proxy server over Firewall here).
因此,我将假设在我的“工作”PC 和 Web 服务器之间存在某种代理服务器。其中我无法访问。(假设代理服务器通过防火墙在这里)。
[10:33:15 GMT+0000 (GMT Standard Time)] SignalR: Client subscribed to hub 'notificationhub'.
[10:33:15 GMT+0000 (GMT Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D'. [10:33:16 GMT+0000 (GMT Standard Time)] SignalR: webSockets transport starting. [10:33:16 GMT+0000 (GMT Standard Time)] SignalR: Connecting to websocket endpoint 'ws://blah/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=IxxvgxBhvbsruv2uk0pK%2FPB708bJGvoOJD0oR0vVPgBip%2B7uGy68HEMOw1ikq7%2BuiyX7XqN%2FwYK%2BKgkrBlz9HHuI5HSDQEwRHvSr2Ey1pg2B7FaviRLFcNu8mg2dRWHVKbAkdw%3D%3D&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D&tid=6'. [10:33:16 GMT+0000 (GMT Standard Time)] SignalR: Websocket opened. [10:33:16 GMT+0000 (GMT Standard Time)] SignalR: webSockets transport connected. Initiating start request. [10:33:16 GMT+0000 (GMT Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state. [10:33:16 GMT+0000 (GMT Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000 hub start, connection id=7f3eba16-9e7b-450e-a740-a69fa91047b6
[10:33:15 GMT+0000(GMT 标准时间)] SignalR:客户端订阅了集线器“notificationhub”。
[10:33:15 GMT+0000(GMT 标准时间)] SignalR:与“/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D”协商。[10:33:16 GMT+0000(GMT 标准时间)] SignalR:webSockets 传输开始。[十时33分16秒GMT + 0000(GMT标准时间)] SignalR:连接到的WebSocket端点“WS://嗒嗒/ signalr /连接传输的WebSockets =&clientProtocol = 1.5&connectionToken = IxxvgxBhvbsruv2uk0pK%2FPB708bJGvoOJD0oR0vVPgBip%2B7uGy68HEMOw1ikq7%2BuiyX7XqN%2FwYK%2BKgkrBlz9HHuI5HSDQEwRHvSr2Ey1pg2B7FaviRLFcNu8mg2dRWHVKbAkdw %3D%3D&connectionData=%5B%7B%22name%22%3A%22notificationhub%22%7D%5D&tid=6'。[10:33:16 GMT+0000(GMT 标准时间)] SignalR:Websocket 打开。[10:33:16 GMT+0000(GMT 标准时间)] SignalR:已连接 webSockets 传输。发起启动请求。[10:33:16 GMT+0000(GMT 标准时间)] SignalR:启动请求成功。过渡到连接状态。[10:33:16 GMT+0000(GMT 标准时间)] SignalR:现在监控保持连接,警告超时为 13333.333333333332,保持连接超时为 20000,断开连接超时为 30000 集线器启动,连接 id=7f3eba16-9e7b-450e a740-a69fa91047b6

