title: SignalR - How can I call Hub Method on server from server
body: <p>I have SignalR working between an ASP.NET (formerly MVC) server and a Windows Service client in the sense that the client can call methods on the Server Hub and then display to Browsers. The Hub code is:</p>
  
  <pre><code>  public class AlphaHub : Hub
          {
              public void Hello(string message)
              {
                  // We got the string from the Windows Service 
                  // using SignalR. Now need to send to the clients
                  Clients.All.addNewMessageToPage(message);
  
                  // Call Windows Service
                  string message1 = System.Environment.MachineName;
                  Clients.All.Notify(message1);
  
  
              }
       public void CallForReport(string reportName)
       {
            Clients.All.CallForReport(reportName);
       }
  </code></pre>
  
  <p>On the client (Windows Service) I have been calling methods on the Hub:</p>
  
  <pre><code>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);
                  // Invoke method on hub
  
                  await alphaProxy.Invoke("Hello", "Message from Service - ConnectionID: " + cid + " - " + System.Environment.MachineName.ToString() + " " + DateTime.Now.ToString());
  </code></pre>
  
  <p>Now, suppose this scenario: The user wll go a particular ASP.NET form like Insured.aspx on the server. In that I want to call CallForReport and then call this method on the client:</p>
  
  <pre><code> public void CallFromReport(string reportName)
          {
              eventLog1.WriteEntry(reportName);
          }
  </code></pre>
  
  <p>How do I get a connection to my own Hub on the server and call the method. I tried the following things from Insured.aspx:</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
          {
              // Hubs.AlphaHub.CallForReport("Insured Report");
              // IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext&lt;AlphaHub&gt;();
              // hubContext.Clients.All.CallForReport("Insured Report");
          }
  </code></pre>