title: Connecting to Azure SignalR Hub from .Net Framework Web App, Console App
body: <p>I have a .Net Framework Web Application (v 4.6.1) that currently uses ASP.Net SignalR. I'm trying to add another SignalR Hub, but allow this one to connect using the <em>Azure SignalR Service</em> so that we can use the REST API to send one-way messages to end-users.</p>
  
  <p>I've been following these examples <a href="https://github.com/vavjeeva/AzureSignalRConsoleApp" rel="nofollow noreferrer">here</a> and <a href="https://github.com/aspnet/AzureSignalR-samples" rel="nofollow noreferrer">here</a> to implement the feature.</p>
  
  <p>There's 3 basic parts</p>
  
  <ul>
  <li>Connect to the hub (<em>half</em> working)</li>
  <li>Send messages through the REST API (working successfully)</li>
  <li>Receive messages as an end-user (<strong>not</strong> working)</li>
  </ul>
  
  <p>The Hub and Azure SignalR Service have been created and are simple, no need to display.</p>
  
  <p><strong>Code Samples</strong></p>
  
  <p><strong>Hub Connection in .Net Framework Web App <em>Startup.cs</em></strong></p>
  
  <pre><code>app.MapAzureSignalR(GetType().FullName, new HubConfiguration { EnableDetailedErrors = true },
      options =&gt;
      {
          options.ConnectionString =
                      ConfigurationManager.ConnectionStrings["AzureSignalR"].ConnectionString;
      });
  </code></pre>
  
  <p><code>MapAzureSignalR</code> comes from <a href="https://www.nuget.org/packages/Microsoft.Azure.SignalR.AspNet/1.0.0-preview1-10317" rel="nofollow noreferrer">this nuget package</a></p>
  
  <p>I've also got client-side JavaScript to handle hub connections and events, this has been up-and-running for a few months with standard ASP.Net SignalR.</p>
  
  <p>The client side connection logs the following information:</p>
  
  <pre><code>Error: You are using a version of the client that isn't compatible with the server. Client version 1.5, server version 2.0.
  at Object.error (jquery.signalR.js:179)
  at Object.success (jquery.signalR.js:728)
  at i (scripts.bundle.js:2)
  at Object.fireWith [as resolveWith] (scripts.bundle.js:2)
  at A (scripts.bundle.js:4)
  at XMLHttpRequest.&lt;anonymous&gt; (scripts.bundle.js:4)
  at XMLHttpRequest.wrapFn (zone.js:1166)
  at ZoneDelegate.invokeTask (zone.js:421)
  at Zone.runTask (zone.js:188)
  at ZoneTask.invokeTask [as invoke] (zone.js:496)
  </code></pre>
  
  <p>Web App has the following packages:</p>
  
  <pre><code>  &lt;package id="Microsoft.AspNet.SignalR" version="2.4.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNet.SignalR.Core" version="2.4.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNet.SignalR.JS" version="2.4.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNet.SignalR.SqlServer" version="2.2.2" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.SignalR.SystemWeb" version="2.4.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNetCore.Authentication.Abstractions" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Authorization" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Authorization.Policy" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Connections.Abstractions" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Hosting.Abstractions" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Hosting.Server.Abstractions" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Http" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Http.Abstractions" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Http.Connections" version="1.0.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Http.Connections.Client" version="1.0.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Http.Connections.Common" version="1.0.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Http.Extensions" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Http.Features" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Routing" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.Routing.Abstractions" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.SignalR" version="1.0.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.SignalR.Common" version="1.0.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.SignalR.Core" version="1.0.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.SignalR.Protocols.Json" version="1.0.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.WebSockets" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.AspNetCore.WebUtilities" version="2.1.0" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.Azure.SignalR" version="1.0.6" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.Azure.SignalR.AspNet" version="1.0.0-preview1-10317" targetFramework="net461" /&gt;
    &lt;package id="Microsoft.Azure.SignalR.Protocols" version="1.0.6" targetFramework="net461" /&gt;
  </code></pre>
  
  <p><strong>Hub Connection in .Net Framework Console App</strong></p>
  
  <pre><code>var serviceUtils = new ServiceUtils(ConfigurationManager.ConnectionStrings["Azure:SignalR:ConnectionString"].ConnectionString);
  
  var url = GetClientUrl(serviceUtils.Endpoint);
  
  _connection = new HubConnection(url)
  {
      ConnectionToken = serviceUtils.GenerateAccessToken(url, userId)
  };
  
  IHubProxy proxy = _connection.CreateHubProxy(hubName);
  
  proxy.On("broadcastMessage", (string server, string message) =&gt;
  {
      Console.WriteLine($"[{DateTime.Now.ToString()}] Received message from server {server}: {message}");
  });
  
  
  _connection.Start();
  </code></pre>
  
  <p>When logging the connection state it displays <em>Disconnected, Connecting, Disconnected</em>.</p>
  
  <p><strong>.Net Core Code Sample</strong></p>
  
  <pre><code>var serviceUtils = new ServiceUtils(connectionString);
  
  var url = GetClientUrl(serviceUtils.Endpoint);
  
  _connection = new HubConnectionBuilder()
      .WithUrl(url, options =&gt;
      {
          options.AccessTokenProvider = () =&gt;
              {
                  return Task.FromResult(serviceUtils.GenerateAccessToken(url, userId));
              };
      }).Build();
  
  _connection.On("broadcastMessage", (string server, string message) =&gt;
  {
      Console.WriteLine($"[{DateTime.Now.ToString()}] Received message from server {server}: {message}");
  });
  
  await _connection.StartAsync(CancellationToken.None);
  </code></pre>
  
  <p>This connects successfully and received messages from my REST API broadcast (see below)</p>
  
  <p><strong>REST API Broadcast</strong></p>
  
  <pre><code>var url = $"{authenticationUtility.Endpoint}/api/v1/hubs/{hubName.ToLower()}";
  var request = new HttpRequestMessage
  {
      Method = HttpMethod.Post,
      RequestUri = new Uri(url)
  };
  
  request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authenticationUtility.GenerateAccessToken(url, sender));
  request.Headers.Accept.Clear();
  request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  request.Headers.AcceptCharset.Clear();
  request.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue("UTF-8"));
  
  var content = JsonConvert.SerializeObject(new MessageContent{ Target = "broadcastMessage", Arguments = new []{ sender, message}});
  request.Content = new StringContent(content, Encoding.UTF8, "application/json");
  var response = await httpClient.SendAsync(request);
  </code></pre>
  
  <p>This returns a <code>202 Accepted</code> code like I expect and sends the message to the .Net Core Console App.</p>
  
  <p>On my Azure portal, I'm able to see connections but I'm not able to receive messages in my Web App's Hub Connection</p>