title: Accessing SignalR Hub in Web App from Windows Service
body: <p>I've created a SignalR hub and have it working within my web app. Now I'm trying to get a separate Windows service to send a message to that hub. Depending on what I use for the hub connection URL, I get 401 Unauthorized, or a SocketException. What am I missing to get the Windows service to be able to send a message to the hub?</p>
  
  <p>Startup class in web app:</p>
  
  <pre><code>[assembly: OwinStartup(typeof(MmaWebClient.Startup))]
  namespace MmaWebClient
  {
      public class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              app.MapSignalR();
          }
      }
  }
  </code></pre>
  
  <p>Hub class in web app:</p>
  
  <pre><code>[HubName("scannerHub")]
  public class ScannerHub : Hub
  {
      public void Send(string message)
      {
          Clients.All.broadcastMessage(message);
      }
  }
  </code></pre>
  
  <p>Script references in index.html:</p>
  
  <pre><code>&lt;script src="../scripts/jquery-1.9.1.js"&gt;&lt;/script&gt;
  &lt;script src="../scripts/jquery.signalR-2.2.0.min.js"&gt;&lt;/script&gt;
  &lt;script src="../signalr/hubs"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>JavaScript (that works) in my AngularJS controller:</p>
  
  <pre><code>    if (!$scope.state.hub) {
          $scope.state.hub = $.connection.scannerHub;
          $scope.state.hub.client.broadcastMessage = function (message) {
              onSubIdOrCassetteIdEntered(scanText);
          }
          $.connection.hub.start()
              .done(function () {
                  console.log('Connected to SignalR. Connection ID: ' + $.connection.scannerHub.connection.id +
                      '. URL: ' + $.connection.scannerHub.connection.baseUrl +$.connection.scannerHub.connection.appRelativeUrl);
              })
              .fail(function (response) {
                  showInfoModal.show('Connection to SignalR Failed', 'This connection is necessary to read the ' +
                      'scans from the scanner. Response message: ' + response.message);
              });
      }
  </code></pre>
  
  <p>And, finally, in the Windows service:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          AutoResetEvent scanReceivedEvent = new AutoResetEvent(false);
  
          var connection = new HubConnection("http://localhost/MmaWebClient/signalr");
          //Make proxy to hub based on hub name on server
          var myHub = connection.CreateHubProxy("scannerHub");
          //Start connection
  
          connection.Start().ContinueWith(task =&gt; {
              if (task.IsFaulted) {
                  Console.WriteLine("There was an error opening the connection:{0}",
                                    task.Exception.GetBaseException());
              } else {
                  Console.WriteLine("Connected");
              }
  
          }).Wait();
  
  
          myHub.On&lt;string&gt;("broadcastMessage", param =&gt; {
              Console.WriteLine("Scan received from server = [{0}]", param);
              scanReceivedEvent.Set();
          });
  
          string input = "";
  
          do
          {
              Console.WriteLine("Enter a value to send to hub or Q to quit.");
  
              input = Console.ReadLine();
  
              if (input.ToUpperInvariant() != "Q")
              {
                  myHub.Invoke&lt;string&gt;("Send", input);
                  scanReceivedEvent.WaitOne(1000);
              }
  
          } while (input.ToUpperInvariant() != "Q");
  
          connection.Stop();
      }
  </code></pre>
  
  <p>When I create the new hub connection in the above code, I've tried these three URLs without success:</p>
  
  <pre><code>var connection = new HubConnection("http://localhost/MmaWebClient/signalr");
  var connection = new HubConnection("http://localhost:8080");
  var connection = new HubConnection("http://localhost");
  </code></pre>
  
  <p>First URL: 401 Unauthorized<br>
  Second URL: Socket Exception<br>
  Third URL: 404 Not Found</p>