Tag: signalr

使用SignalR时,mscorlib.dll中出现“System.AggregateException”

请考虑以下代码: using Microsoft.AspNet.SignalR.Client; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Stock { public string Symbol { get; set; } public decimal Price { get; set; } } class Program { static void Main(string[] args) { var hubConnection = new HubConnection(“http://www.contoso.com/”); IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy(“StockTickerHub”); stockTickerHubProxy.On(“UpdateStockPrice”, stock => Console.WriteLine(“Stock […]

有没有办法检查SignalR服务器/集线器是否处于活动/启动/准备/通过服务器端代码接受连接?

我有一个控制台应用程序连接到SignalR Hub并发送消息等。工作完全正常。 今天,当我启动我的控制台应用程序时,我忘了 – 也 – 启动我的SignalR集线器(因此没有集线器,活动和接受/发送消息)。 当然,我得到了一个低级连接错误: 服务器正在积极拒绝连接等… 有没有办法可以检查Hub是否在线,活动并接受连接? 或者是使用try / catch的唯一方法,并假设任何捕获,它是脱机的? 这是我的示例代码: _hubConnection.Start().ContinueWith(task => { if (task.IsFaulted) { WriteLine( string.Format(” !!! There was an error opening the connection:{0}”, task.Exception.GetBaseException()), ConsoleColor.Red); } else { WriteLine(” * Connected to the Hub @ http://localhost:80″); } }).Wait(); 干杯!

SignalR:必须先启动连接,然后才能发送数据。 在.send()之前调用.start()

直到最近才开始使用SignalR,我几天前就已经开始工作,现在无法解决出错的问题。 我有我的中心: [HubName(“roleManagementHub”)] public class RoleManagementHub : GenericHub { public RoleManagementHub(ICurrentlyViewingUserService service) : base(service) { } } 这扩展了我创建的通用集线器: public class GenericHub : Hub where TEntity : class, IBusinessObject { private readonly ICurrentlyViewingUserService service; public GenericHub(ICurrentlyViewingUserService service) { this.service = service; } public void ImViewing(string id) { string colour; service.AddCurrentlyViewingUser(id, HttpContext.Current.User.Identity.Name, out colour); Clients.handleImViewingMessage(HttpContext.Current.User.Identity.Name, colour, id); […]

VS2012注册和dependency injection中的SignalR 2.0

我能够使用我自己的DI与SignalR 1.13一起工作: //Funq container GlobalHost.DependencyResolver = new FunqDependencyResolver(container); RouteTable.Routes.MapHubs(); 现在有了新版本2.0,我被困住了。 using Microsoft.Owin; using Owin; //SignalR 2.0 no longer uses RouteTable.Routes.MapHubs(); [assembly: OwinStartup(typeof(SignalRChat.Startup))] namespace SignalRChat { public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } } (VS2013中的新SignalR 2.0设置截图) 首先,它是VS2013的屏幕。 我的VS2012 Pro没有Create New …-> OWIN Startup类。我手写了一个。 但是现在我如何调用新的启动类来替换旧的MapHub()函数? 其次,我正在使用运行其余Web项目的DI。 我如何现在将signalR注册到我的DI? 编辑——————————————– 问题还有一点。 我在Global.asax.cs-> Application_Start()中创建了我的DI容器,但是自动创建并调用了SignalR Startup.cs-> […]

SignalR跨域和IIS 7.5到集线器的路径只能在服务器上本地工作,如何从外部访问它?

我在我的C#WinForms应用程序中自我托管SignalR Hubs服务器: string url = “http://localhost:8081/”; m_signalrServer = new Microsoft.AspNet.SignalR.Hosting.Self.Server(url); // Map the default hub url (/signalr) m_signalrServer.MapHubs(); // Start the SignalRserver m_signalrServer.Start(); 我的ASP.NET Web应用程序充当SignalR Hubs JavaScript客户端: $(document).ready(function() { $.connection.hub.url = ‘http://localhost:8081/signalr’ var myHub = $.connection.myHub; $.connection.hub.error(function () { console.log(“Error!”); }); $.connection.hub.start() .done(function () { console.log(“Connected!”); }) .fail(function () { console.log(“Could not connect!”); }); }); […]

使用SignalR广播消息时忽略客户端

我想忽略提出请求广播我的网络应用程序的消息的客户端。 我似乎可以这样做的唯一方法是缓存当前用户的connectionId: public class BroadcastHub : Hub { public override Task OnConnected() { System.Runtime.Caching.MemoryCache.Default.Set(HttpContext.Current.User.Identity.Name + “-connectionId”, Context.ConnectionId, new CacheItemPolicy() { Priority = CacheItemPriority.Default, SlidingExpiration = TimeSpan.FromHours(1), AbsoluteExpiration = MemoryCache.InfiniteAbsoluteExpiration }); return base.OnConnected(); } public override Task OnReconnected() { System.Runtime.Caching.MemoryCache.Default.Set(HttpContext.Current.User.Identity.Name + “-connectionId”, Context.ConnectionId, new CacheItemPolicy() { Priority = CacheItemPriority.Default, SlidingExpiration = TimeSpan.FromHours(1), AbsoluteExpiration = MemoryCache.InfiniteAbsoluteExpiration }); […]

将SignalR中的对象列表发送到JavaScript方法

我在ASP和SignalR中编写多人游戏(Monopoly)。 我已停在页面上,其中包含一个包含游戏列表的表格。 我不知道我是否正确行事:)所以,这是我到目前为止所做的事情,我需要帮助继续前进: 我用空表创建了GamesList WebForm页面: # Number of players Players Theme Join 我的目标是在页面加载时填充此表。 数据应由集线器提供: GamesListHub.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.AspNet.SignalR; using Newtonsoft.Json; namespace Obipoly.Hubs { public class GamesListHub : Hub { public List games = new List() { new GamesItem(2, “Theme1”, “User1”), new GamesItem(4, “Theme3”, “User2”) }; //just for tests […]

是否可以在SignalR集线器方法中返回预编码的JSON字符串?

在MVC项目中,我在类似于此的集线器上有一个方法: public string Foo() { return DoCrazyThingThatReturnsJson(); } 不幸的是,SignalR(或其他东西)接受编码的JSON字符串并愉快地对其进行编码,然后将其返回,因此浏览器就像LOLWTF。 有没有办法跳过第二次编码?

SignalR Context.User.Name返回空

每当我尝试从Hub访问Context.User.Identity ,用户详细信息始终为空。 注意: Context.User不返回null,属性只是空的: 我已经看了很多关于SO的问题,但是所有这些问题似乎都在问为什么Context.User为null ,答案是移动app.MapSignalR(); 在ConfigureAuth();下面ConfigureAuth(); ,正如我所做的那样: public void Configuration(IAppBuilder app) { ConfigureAuth(app); app.MapSignalR(); } HttpContext.Current.User也返回空,但同样只返回一个Hub 。 如果我从任何其他Controller调用它,我会获得当前登录的用户详细信息。 最后,我还发现HttpContext.Current.User.IsAuthenticated是false令人不安,但用户仍然可以访问该函数。 (请参阅上面屏幕截图中的Authorize属性。) 是否有人能够解释为什么我的用户是空的? 非常感谢所有帮助。

SignalR 2长轮询“协议”请求在未在本地运行时超时

目前我有一个非常健谈的应用程序,需要得到Singleton的支持(参见下面的代码)。 我升级到SignalR 2.0并遵循升级指南,但在将其部署到环境后,有时所有对“协议”的请求都会失败,信号器会中断,当它没有中断时,推送速度非常慢从服务器向客户端发送通知,也许这与使用长轮询有关? 这是我的服务器端代码的样子。 Owin中的配置方法启动类 var hubConfig = new HubConfiguration(); hubConfig.EnableDetailedErrors = true; GlobalHost.DependencyResolver.UseSqlServer(ConfigurationManager.AppSettings[“ConnectionString”].ToString()); app.MapSignalR(hubConfig); 如您所见,我正在使用SQL背板。 这是我的Hub的样子 public class MyHub : Hub { public void JoinGroup(int someId) { Groups.Add(Context.ConnectionId, someId.ToString()); } public void LeaveGroup(int someId) { Groups.Remove(Context.ConnectionId, someId.ToString()); } } 这里要说的另一点是我正在使用群组。 这可能是问题的一部分,我注意到群组似乎让事情变得更慢,好像信号器正在等待群组中的所有用户在推出通知后完成。 我的Singleton看起来像这样。 public class Broadcaster { private readonly static Lazy _instance = new Lazy(() […]