I have SignalR running between an ASP.NET server (formerly MVC) and a Windows service client in the sense that the client can call methods on a hub server and then display them in browsers. Hub Code:
public class AlphaHub : Hub
{
public void Hello(string message)
{
Clients.All.addNewMessageToPage(message);
string message1 = System.Environment.MachineName;
Clients.All.Notify(message1);
}
public void CallForReport(string reportName)
{
Clients.All.CallForReport(reportName);
}
On the client (Windows service), I called methods on the hub:
var hubConnection = new HubConnection("http://localhost/AlphaFrontEndService/signalr",
useDefaultUrl: false);
IHubProxy alphaProxy = hubConnection.CreateHubProxy("AlphaHub");
await hubConnection.Start();
string cid = hubConnection.ConnectionId.ToString();
eventLog1.WriteEntry("ConnectionID: " + cid);
await alphaProxy.Invoke("Hello", "Message from Service - ConnectionID: " + cid + " - " + System.Environment.MachineName.ToString() + " " + DateTime.Now.ToString());
Now suppose this scenario: the user will use a specific form of ASP.NET, such as Insured.aspx on the server. In this, I want to call CallForReport, and then call this method on the client:
public void CallFromReport(string reportName)
{
eventLog1.WriteEntry(reportName);
}
How can I get a connection to my own hub on the server and call the method. I tried the following things from Insured.aspx:
protected void Page_Load(object sender, EventArgs e)
{
}
source
share