signalr

Is it possible to return a pre-encoded JSON string in a SignalR hub method?

我是研究僧i 提交于 2019-12-06 00:47:14
In an MVC project, I have a method on a hub similar to this: public string Foo() { return DoCrazyThingThatReturnsJson(); } Unfortunately SignalR (or something) takes the encoded JSON string and happily encodes it, then returns it, so browser be like LOLWTF. Is there a way to skip this second encoding? Looking at this here : We assume that any ArraySegment is already JSON serialized it seems like something like this may work (note that I haven't tried it, so no promises): string jsonString = ...; // your serialized data var jsonBytes = new ArraySegment<byte>(Encoding.UTF8.GetBytes(jsonString));

How to notify database changes with signalR

本秂侑毒 提交于 2019-12-06 00:23:35
I've just started with SignalR and would like to try out the real time notifications. The objective is to keep displaying the updated message on web page. There is a database table - DummyData with a column Message . This table has only one record - Hello When the page loads, "Hello" is displayed. I then manually run the command in sql server 2012 update DummyData set Message='hello world' , but the message isn't updated in the webpage. aspx: <script> $(function () { var notify = $.connection.notificationsHub; $.connection.hub.start().done(function () { notify.server.notifyAllClients(); });

ASP.NET Core 2.2 WebApi 系列【九】使用SignalR

假装没事ソ 提交于 2019-12-06 00:09:10
1. 添加 SignalR 客户端库 右键点击项目->然后选择“添加” >“客户端库” 提供程序选择: unpkg ,库选择: @aspnet/signalr@1.1.4 选择“选择特定文件” ,展开“dist/browser” 文件夹,然后选择“signalr.js” 和“signalr.min.js” 选择指定位置安装即可 2.定义Hub集线器 创建MessageHub 并继承Hub。 Hub 类管理连接、组和消息 using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; namespace NetCoreWebApi.SignalR { /// <summary> /// Message集线器 /// </summary> public class MessageHub : Hub { /// <summary> /// 存放已连接信息 /// </summary> public static readonly Dictionary<string, string> Connections = new Dictionary<string, string>(); /// <summary> /// 发送消息 /// </summary> /

SignalR - How to perform async Task in hub?

痴心易碎 提交于 2019-12-05 23:19:55
问题 I am trying to create a SignalR application using the C# 5 async/await features, but whenever the code is run, it will throw an System.InvalidOperationException. Here is the simplest code to reproduce the problem. public class SampleHub : Hub { public Task<string> GetGoogle() { var http = new WebClient(); return http.DownloadStringTaskAsync("http://www.google.com"); } } Exception details: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started

Does SignalR support the Publish/Subscribe messaging paradigm?

蓝咒 提交于 2019-12-05 23:15:52
I want to use pub-sub messaging between multiple servers in a web farm to maintain their local (ASP.NET) caches in sync. Could this be easily done with SignalR? If it is possible, how can I do so? 来源: https://stackoverflow.com/questions/9449601/does-signalr-support-the-publish-subscribe-messaging-paradigm

Unexpected Signalr connection abort in Firefox

风格不统一 提交于 2019-12-05 23:01:17
问题 I am using SignalR (with cross-domain request), version 2.3.0 for webchat integrated to ASP.NET site. Everything is working fine. But I found strange behaviour of SignalR connection. When I clicked to the reference from tab of the chat for file downloading SignalR connection was aborted and onDisconnected method was triggered in my Hub class. FireBug show me next POST-request: http://*:81/signalr/abort?transport=longPolling&clientProtocol=1.4&token

How to make SignalR behave gracefully in case of disconnection

萝らか妹 提交于 2019-12-05 22:55:47
My application will often be used under fucked up corporate networks (proxy, firewalls, etc.) so I can not rely on sockets and long-polling is practically my only option. Here is my biggest problem with long-polling: Long-polling is disconnected at some point of time I automatically reconnect (accoring to documentation) User clicks something that causes hub method call but connection is not established yet - error happens. Is there any way to synchronize hub method call and reconnection like: I call hub method SignalR sees connection is not ready yet It waits till connection is ready and calls

SignalR .NET Core camelCase JSON Contract Resolver

a 夏天 提交于 2019-12-05 22:04:28
问题 Using .NET Core RC2. Got SignalR working, but trying to get it returning camelCase properties in JSON. For APIs I'm using... services.AddMvc().AddJsonOptions(o => { o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); Maybe there's just nothing in place yet for SignalR (after all, it's not even supposed to work yet...), but wondering if anyone's figured it out yet? I've tried a few things like... services.AddTransient<IContractResolver,

SignalR push-notification to specific client with MVC4

旧巷老猫 提交于 2019-12-05 22:00:58
问题 I am trying to use SignalR with MVC4 c# project to send push notification to selected clients only. For this I am using 'context.Clients.Client' by storing 'Context.ConnectionId' in c# static variable {since unable to use session with signalr}. But since 'contextConnectionId' is a static variable; the message is still boardcasted to all clients :( Is there any alternative to session with signal or any other elegant way to do this? (found few related post but no specific answers) Code as below

SignalR seems to be slowing startup of my MVC / Azure application

喜夏-厌秋 提交于 2019-12-05 18:54:10
I have an MVC application running under .NET 4.5 on a WebRole on Windows Azure, employing SignalR 1.0 -alpha2, and using the ServiceBus backplane. In my App_Start folder I have RegisterHubs.cs, as follows: [assembly: PreApplicationStartMethod(typeof(pageengine.studio.RegisterHubs), "Start")] namespace pageengine.studio { public static class RegisterHubs { public static void Start() { // Register the default hubs route: ~/signalr/hubs RouteTable.Routes.MapHubs(); } } } And in Global.asax, I have the following: protected void Application_Start() { AreaRegistration.RegisterAllAreas();