This project is read-only.

SinalR in an Orchard 1.9 Module?

Topics: Customizing Orchard, General, Writing modules
Aug 4, 2015 at 12:29 PM
Hi All, just wanting to know if anyone has been successful in incorporating signalr into an orchard 1.9+ module?
I've attempted to update both NGM.SignalR and Proligence.SignalR without any luck - though I have a feeling nuget is more responsible for the failures than anything - to attempt to be able to do so. Has anyone been successful, and if so, would be willing to give me a few pointers? Very interested in any forthcoming information, big thanks - Liv
Aug 5, 2015 at 7:45 AM
Edited Aug 5, 2015 at 7:45 AM
Ok, so I have Proligence.SignalR working with samples functioning as [I assume] they should [Nuget was not my friend in this instance, manually copying dll's did the trick]. Problem is, with a module I created myself - I only ever get:

Protocol error: Unknown transport.

...with no other information to initiate any form of debug process.

Therefore, I attempted to copy Piotr's sample code "Benchmark" into my module [which works as per above], though it throws the same error as well?

Is there anything specific I have to do to my module in order to get it to work? Any advice would be greatly appreciated - Big thanks, Liv
Aug 5, 2015 at 9:41 AM
Edited Aug 5, 2015 at 9:44 AM
Hi Liv,

No, nothing specific is required. If you are not able to run any of those modules (and these are pretty similar), it may indicate a problem with your code (or a mismatch between latest SignalR and Orchard 1.9.x in general). But if you'd be able to provide repro steps, that would be great.

Please grab the latest code from our BitBucket repo, if you haven't yet. The Gallery version is very old.
Regarding NuGet - we're not using it in our modules (all libs are referenced manually and included in the repo), so I don't get the point here. Please check if you are not referencing somewhere a different version of some lib we already use. Best way to narrow it down is to go to /App_Data/Dependencies and checking if you have some assemblies mismatching those in /Modules/Proligence.SignalR/bin. If so, then it's sitting there somewhere in /Modules/*/bin folder and needs to be dealt with.

SignalR error messages are not too verbose, plus debugging a massively async code is tough, hence I'd be grateful if you could provide some repro steps with more detail about your setup.
Aug 5, 2015 at 10:45 AM
Thanks pszmyd, after a little trial and error, I can now get your sample code to work in my module - but only if your 'Signalr Samples' is enabled as well it seems [I'm using the latest repo anlong with 1.9.1.x. I need to test further to make 100% sure, so I thought I'd implement some tutorial code to eliminate my error prone coding - but even with this I seem to have struck a problem: the codes controller action is not called by getAllMessages[ajax], although the transport error has gone away.

$(function () {
    // Declare a proxy to reference the hub.
    var notifications = $.connection.messagesHub;

    // Create a function that the hub can call to broadcast messages.
    notifications.client.updateMessages = function () {
    // Start the connection.
    $.connection.hub.start().done(function () {
        alert("connection started");
    }).fail(function (e) {

function getAllMessages() {
    var tbl = $('#messagesTable');
        url: '@Url.Action("GetMessages", "Home", new { area = "test.SignalR" })', //'/home/GetMessages',
        contentType: 'application/html ; charset:utf-8',
        type: 'GET',
        dataType: 'html'
    }).success(function (result) {
    }).error(function (e) {
        alert("Error:" + e);
    public class HomeController : Controller
        private readonly dynamic _shapeFactory;

        public HomeController(IShapeFactory shapeFactory) {
            _shapeFactory = shapeFactory;

        public ActionResult Index()
            return View();

        public ActionResult Test()
            return View();

        public ActionResult Benchmark()
            return View();
        public ActionResult GetMessages()
            MessagesRepository _messageRepository = new MessagesRepository();
            //return PartialView("_MessagesList", _messageRepository.GetAllMessages());
            var messages = _messageRepository.GetAllMessages();

            var shape = _shapeFactory.MessageList(
                Message: messages
            return new ShapeResult(this, shape);
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

namespace test.SignalR.Hubs
    public class MessagesHub : Hub {

        public static void SendMessages()
            IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MessagesHub>();
I will try and get this to work, then start afresh to reproduce[or not] the errors i've been experiencing - many thanks for your support, Liv
Aug 5, 2015 at 11:07 AM
Hi Liv,

Thanks for getting back that fast:)
What transport are you using? Please try to use the "longPolling" one (or any other besides WebSockets) - it's very well explained in the SignalR docs how to explicitly set it. Unfortunately WebSockets, which I assume are kicking in by default now due to much more common support these days, are not supported yet by the module. Those do not fit into Orchard's unit-of-work design and I haven't yet cracked how to make those two work together easily (with websockets SignalR starts up a totally separate thread that processes all communication and, at least a few months back, it was not possible to easily plug into this pipeline).
Aug 6, 2015 at 9:26 AM
Ok, i'm pretty sure I have followed all your advice, but I'm still not getting the broadcast function to fire 'updateMessages'. I have spent much time trying different things but I'm officially stumped?

I thought I'd upload the tiny test proj to: so you could see if I've done something ridiculous [note it has some of your example code 'Benchmark' which I believe works correctly in it as well.]

Any thoughts? Thanks for your time - much appreciated, Liv
Aug 6, 2015 at 8:16 PM
Ahh, after looking at your code twice I might have found the culprit. Please do not use the static GlobalHost.ConnectionManager. Inject IConnectionManager in hub constructor (like with any other dependency in other Orchard classes) instead.
Aug 7, 2015 at 1:39 AM
Oh.....Fantastic, all works now thanks to your help - you're awesome!

So re: your module - I cloned both your latest and Orchard's latest branch and only had to perform trivial tasks on your module [ that mine is working and I didnt go amending else where embarrassed ;) ]

So the only amendments I made for it to work, were:
I have noticed, though I'm not sure if it has happened everytime, that upon first initialization of my module - it doesnt seem to get wired up correctly and I have to restart Orchard - where it seems to work fine thereafter; though this could be my doing, I really need to repeat the process with just your samples to see if it happens as well. Anyhow, I'll keep you posted - so thanks again for your efforts, so very impressive. Liv
Aug 8, 2015 at 2:03 AM
Cool, glad you made it all work!

Regarding the issues:
  • Yeah, the compatibility issue you mentioned is something I'll fix soon. Got a bit behind with the latest Orchard codebase and need to catch up.
  • JetBrains.Annotations reference is also something that got recently changed in Orchard core - will fix this as well.
About the restart issue - it might be due to various reasons. Actual setup (IIS vs IIS Express), config (one may disable automatic module discovery via config files etc.) and so on. Can you please share your setup info? I might be able to give you some hints.