Reputation: 305
I'm trying to send a message via SignalR from my WebRole to the client but it's not appearing. It appears fine when I test call it from a Controller, but when called from the Run() function, it doesn't seem to make it over to the client.
public override void Run()
{
processingQueueClient.OnMessage((message) =>
{
message.Complete();
MainHub.Send("Test 1");
});
completedEvent.WaitOne();
}
namespace MainWebRole
{
public class MainHub : Hub
{
public static void Send(string message)
{
var context = GlobalHost.ConnectionManager.GetHubContext<MainHub>();
context.Clients.All.broadcastMessage(message);
}
}
}
<script>
$(function () {
var chat = $.connection.mainHub;
chat.client.broadcastMessage = function (message) {
var notificationText = "<div><button type=\"button\" class=\"btn btn-default\" onclick=\"onClickClearComplete()\">Clear Complete</button></div><div class=\"spacer10\"></div><div><table class=\"table table-bordered\">";
notificationText += "<tr><td nowrap><span><i class=\"fa fa-pause\"></i> Pending \"" + message + "\"</span></td></tr>";
notificationText += "</table></div>";
$("#statusText").html(notificationText);
};
$.connection.hub.start().done(function () {
});
});
</script>
Upvotes: 0
Views: 231
Reputation: 3293
Please try to run your signalR send function via below steps:
1) Install-Package Microsoft.AspNet.SignalR.Client
2) write below code in Azure web role in run function.
HubConnection _hub = new HubConnection("http://localhost:1942");
var _proxy = _hub.CreateHubProxy("MainHub");
if (_hub.State == ConnectionState.Disconnected)
{
await _hub.Start();
}
await _proxy.Invoke("Send", "jambor");
http://localhost:1942
is your SignalR server site.
MainHub
is your SignalR hub class name
Send
is your function in MainHub class.
Upvotes: 1