SignalR对消息大小有合理的默认限制,因为它试图成为一个实时消息传递框架,而不是一个web服务框架。
我有一个.NET客户端在集线器上调用一个方法,如下所示:
var competition = hubProxy.Invoke<Competition>("GetCompetition", "Queen's Final 2013").Result;
在Windows8上调试,我得到以下错误:
20:23:25.0926734 - null - ChangeState(Disconnected, Connecting)
20:23:25.3748631 - ... - WS: ws://localhost:59570/signalr/connect?transport=webSockets&connectionToken=-Tp4LiB-1w8TjNuw0ilbeMFjw_B8Vl1c31Oni72nbXazWo6qHBSJCRFJU6YD4wJo9dYZ_mb0vNez2hD8JllF0SUXzkhrN4ejcuO1_gBrFrcsK02xJLBnV_z7d774EFlw0&connectionData=[{"Name":"QueensFinalHub"}]
20:23:25.3968761 - ... - ChangeState(Connecting, Connected)
20:23:34.2938036 - ... - WS: OnMessage({})
20:23:35.5546436 - ... - OnError(System.InvalidOperationException: Buffer length exceeded
at Microsoft.AspNet.SignalR.Infrastructure.ByteBuffer.Append(Byte[] segment)
at Microsoft.AspNet.SignalR.WebSockets.WebSocketMessageReader.<ReadMessageAsync>d__0.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 Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<ProcessWebSocketRequestAsync>d__8.MoveNext())
20:23:35.5576456 - ... - WS: OnClose(False)
20:23:35.5596469 - ... - ChangeState(Connected, Reconnecting)
20:23:35.5616483 - ... - WS: ws://localhost:59570/signalr/reconnect?transport=webSockets&connectionToken=-Tp4LiB-1w8TjNuw0ilbeMFjw_B8Vl1c31Oni72nbXazWo6qHBSJCRFJU6YD4wJo9dYZ_mb0vNez2hD8JllF0SUXzkhrN4ejcuO1_gBrFrcsK02xJLBnV_z7d774EFlw0&connectionData=[{"Name":"QueensFinalHub"}]
20:23:35.5766587 - ... - ChangeState(Reconnecting, Connected)
20:23:44.3054789 - ... - WS: OnMessage({})
响应数据相当大,但当我在Windows7上调试时(我认为连接使用服务器端事件),我不会收到这个错误。
是什么原因造成的?
WebSocketHandler::MaxIncomingMessageSize
的默认值为64kb,这是只读属性。
您似乎正在尝试将SignalR用于基本的HTTPGET请求。您有没有考虑过只对ASP.NET WebAPI web服务使用AJAX来进行这种数据交换?