How to send big data via SignalR in .NET client

不羁岁月 提交于 2019-12-01 15:53:42

As you have already gathered - this data is too much for SIGNALR by it's own design.

Would it not be a better idea to rather have another process that does this with a normal REST API (GET/POST). Perhaps a message indicating to the user that this needs to be done, as this feels very 'BATCH' like.

Secondly, if it a requirement (possible wrong tool for the job), have you considered compression.

You can add a line that makes the message size 'infinite 'in your Startup.cs by setting the MaxIncomingWebSocketMessageSize to null:

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
        app.MapSignalR();
        GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null;
        }
    }
} 

Mine works with ~200kb of data, 10 messages send consistently. I don't know how well it works if there is more data send per second though.

Serkan Polat

its easy to do it..

  • split files into byte Array chunks (my tests shows max 10kb per chunk is enough)
  • send chunks to client with an invoke like (calculate totalBytes and the chunk data you have) :

    hubProxy.Invoke("Send", chunk,currentBytes,totalBytes);
    
  • get the chunks from client and create a byte array and append each chunk, signalr sends files syncronously, this means data will be received as your send order
  • you have totalbytes and currentBytes data, now you know all data received, save this byte array to a file with stream or whatever you like..

add this to web config
<httpRuntime maxRequestLength="1048576" executionTimeout="600" />

then add this code to Startup.cs

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.MapSignalR();
        GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!