我在ASPNET MVC 4.0应用程序中将SignalR更新为2.0,现在我收到以下错误:
计数器'消息总线消息已发布总计'在指定的类别中不存在
错误被抛出
app.MapSignalR();
这是我现在在Startup类中使用的代码(之前我使用过RegisterHubs。
public static class Startup
{
public static void Configuration(IAppBuilder app)
{
var signalrDependencyContainer = new WindsorContainer().Install(new HubsInstaller());
var signalrDependency = new SignalrDependencyResolver(signalrDependencyContainer.Kernel);
GlobalHost.DependencyResolver = signalrDependency;
app.MapSignalR();
}
}
更新
以下是所请求代码的部分摘录。
这是我在安装计数器时得到的
PM> signalr ipc
SignalR Utility Version: 1.1.0.0
Installing performance counters...
Connections Connected
Connections Reconnected
Connections Disconnected
Connections Current
Connection Messages Received Total
Connection Messages Sent Total
Connection Messages Received/Sec
Connection Messages Sent/Sec
Message Bus Messages Received Total
Message Bus Messages Received/Sec
Scaleout Message Bus Messages Received/Sec
Messages Bus Messages Published Total
Messages Bus Messages Published/Sec
Message Bus Subscribers Current
Message Bus Subscribers Total
Message Bus Subscribers/Sec
Message Bus Allocated Workers
Message Bus Busy Workers
Message Bus Topics Current
Errors: All Total
Errors: All/Sec
Errors: Hub Resolution Total
Errors: Hub Resolution/Sec
Errors: Hub Invocation Total
Errors: Hub Invocation/Sec
Errors: Tranport Total
Errors: Transport/Sec
Scaleout Streams Total
Scaleout Streams Open
Scaleout Streams Buffering
Scaleout Errors Total
Scaleout Errors/Sec
Scaleout Send Queue Length
Performance counters installed!
StartupOwin.cs
using org.app.Ui.Web.App_Start;
using Microsoft.Owin;
[assembly: OwinStartup(typeof(StartupOwin), "Configuration")]
namespace org.app.Ui.Web.App_Start
{
using Owin;
public class StartupOwin
{
public void Configuration(IAppBuilder app)
{
org.app.Ui.Web.App_Start.StartupSignalR.ConfigureSignalR(app);
}
}
}
StartupSignalR.cs
namespace org.app.Ui.Web.App_Start
{
using Castle.Windsor;
using org.app.Ui.Web.Infrastructure;
using Microsoft.AspNet.SignalR;
using Owin;
public static class StartupSignalR
{
public static void ConfigureSignalR(IAppBuilder app)
{
app.MapSignalR(new HubConfiguration
{
Resolver = new SignalrDependencyResolver(
new WindsorContainer()
.Install(new HubsInstaller()).Kernel)
});
}
}
}
HubNewHandler.cs
namespace org.app.Ui.Web.Hubs
{
using System;
using System.Data.Entity;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Timers;
using Castle.MicroKernel;
using Castle.MicroKernel.Lifestyle;
using Castle.Windsor;
using org.app.Data.Contracts;
using org.app.Data.Model;
using Microsoft.AspNet.SignalR;
public class HubNewHandler : IHubNewHandler
{
private System.Timers.Timer aTimer;
private DateTime lastDate = DateTime.UtcNow;
readonly private IKernel kernel;
public HubNewHandler(IKernel kernel)
{
this.kernel = kernel;
}
public void StartTimer()
{
aTimer = new System.Timers.Timer(10000);
aTimer.Elapsed += new ElapsedEventHandler(SendNewMessage);
aTimer.Enabled = true;
GC.KeepAlive(aTimer);
}
public void SendNewMessage(object state, ElapsedEventArgs elapsedEventArgs)
{
using (kernel.BeginScope())
{
var gdpUow = kernel.Resolve<IGdpUow>();
var gdpTesisConfigurationsRecord = gdpUow.GdpConfigurations.GetByPredicate(a => a.Description.Equals("LastDateTimeMessagesCheck")).SingleOrDefault();
if (gdpTesisConfigurationsRecord == null)
{
gdpTesisConfigurationsRecord = new GdpConfiguration
{
Description = "LastDateTimeMessagesCheck",
DateTimeValue = DateTime.Now.ToUniversalTime()
};
gdpUow.GdpConfigurations.Add(gdpTesisConfigurationsRecord);
}
var lastMessagesDateTimeCheck = gdpTesisConfigurationsRecord.DateTimeValue;
var messagesList = GetShowableMessagesList(gdpUow, lastMessagesDateTimeCheck);
// Get a hub context for ServerHub
var serverHub = GlobalHost.ConnectionManager.GetHubContext<ServerHub>();
// Send a message to all the clients
serverHub.Clients.All.addNewMessagesToMap(messagesList, false);
gdpTesisConfigurationsRecord.DateTimeValue = elapsedEventArgs.SignalTime.ToUniversalTime();
gdpUow.GdpConfigurations.Update(gdpTesisConfigurationsRecord);
gdpUow.Commit();
}
}
}
}
ServerHub.cs
namespace org.app.Ui.Web.Hubs
{
using System;
using System.Linq;
using System.Threading.Tasks;
using Data.Contracts;
using Data.Model;
using Microsoft.AspNet.SignalR;
public class ServerHub : Hub
{
public IGdpUow Uow { get; set; }
public override Task OnConnected()
{
var connectionId = Guid.Parse(Context.ConnectionId);
return base.OnConnected();
}
public override Task OnDisconnected()
{
var connectionId = Guid.Parse(Context.ConnectionId);
return base.OnDisconnected();
}
public override Task OnReconnected()
{
var connectionId = Guid.Parse(Context.ConnectionId);
return base.OnReconnected();
}
public void GetAllMessages()
{
var messagesList = Uow.Messages.GetAll();
Clients.All.addNewMessagesToMap(messagesList, true);
}
}
}
任何想法可能是什么问题? 提前致谢。吉列尔莫。
答案 0 :(得分:1)
对于SignalR 2.0,添加Owin引用。
(注意:我不知道您的应用程序名称,将 yourapplicationname (在代码中提到两次)更改为您的应用程序名称。
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(yourapplicationname.Startup))]
namespace yourapplicationname
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var signalrDependencyContainer = new WindsorContainer().Install(new HubsInstaller());
var signalrDependency = new SignalrDependencyResolver(signalrDependencyContainer.Kernel);
GlobalHost.DependencyResolver = signalrDependency;
app.MapSignalR();
}
}
}
答案 1 :(得分:1)
尝试安装不同版本的Microsoft.AspNet.SignalR.Utils。在安装了utils的1.1.2之后,我收到了这个错误。我卸载了它,并安装了2.1.1版本:
Install-Package microsoft.aspnet.SignalR.Utils -version 2.1.1
然后我再次运行命令:
signalr.exe ipc
最后,我重新启动了我的应用程序并且运行正常。问题似乎是一个版本使用&#34; 消息 总线消息发布总计&#34;和其他用途&#34; 消息 总线消息发布总计&#34; (注意&#34; s&#34;&#34;消息&#34;在第二个中丢失。 See more information here (how's your Korean?)