title: Using the new signalR for DotNet core to send messages from console App to web page
body: <p>I am using this example from  <a href="https://blogs.msdn.microsoft.com/webdev/2017/09/14/announcing-signalr-for-asp-net-core-2-0/" rel="noreferrer">https://blogs.msdn.microsoft.com/webdev/2017/09/14/announcing-signalr-for-asp-net-core-2-0/</a> to create a console app that can send messages from a simple console app to a web page.</p>
  
  <p>Below is the simple example for console application which reads the user input and prints that input on the screen, I want to send the same user input also to the web page.</p>
  
  <pre><code>static void Main(string[] args)
          {
              while (true)
              {
                  Console.WriteLine("Enter input:");
                  string line = Console.ReadLine();
                  if (line == "exit")
                  {
                      break;
                  }
                  sendSignalToClient(line);
                  Console.Write("Message Sent To Client: " + line);
              }
          }
  
          private static void sendSignalToClient(string line)
          {
              //Send a message from this app to web client using signalR
          }
  </code></pre>
  
  <p>I have just started learning about this. Any material or suggestions related to this is appreciated. -Thanks</p>
  
  <p>Edit: I am using a sample signalR chat application.</p>
  
  <pre><code>public class Program
      {
          public static void Main(string[] args)
          {
              BuildWebHost(args).Run();
          }
  
          public static IWebHost BuildWebHost(string[] args) =&gt;
              WebHost.CreateDefaultBuilder(args)
                  .UseStartup&lt;Startup&gt;()
                  .Build();
      }
  
  public class ChatHub : Hub
      {
          public void Send(string name, string message)
          {
              // Call the broadcastMessage method to update clients.
              Clients.All.InvokeAsync("broadcastMessage", name, message);
          }
      }
  
  public class Startup
      {
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddSignalR();
          }
  
          public void Configure(IApplicationBuilder app, IHostingEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
              app.UseFileServer();
  
              app.UseSignalR(routes =&gt;
              {
                  routes.MapHub&lt;ChatHub&gt;("chat");
              });
          }
  </code></pre>
  
  <p>Below is the code for the console application that is sending messages to web page</p>
  
  <pre><code>class Program : Hub
  {
      static void Main(string[] args)
      {
          Task.Run(Run).Wait();
      }
  
      static async Task Run()
      {
          var connection = new HubConnectionBuilder()
              .WithUrl("http://localhost:59768/chat")
              .WithConsoleLogger()
              .WithMessagePackProtocol()
              .WithTransport(TransportType.WebSockets)
              .Build();
  
          await connection.StartAsync();
  
          Console.WriteLine("Starting connection. Press Ctrl-C to close.");
          var cts = new CancellationTokenSource();
          Console.CancelKeyPress += (sender, a) =&gt;
          {
              a.Cancel = true;
              cts.Cancel();
          };
  
          connection.Closed += e =&gt;
          {
              Console.WriteLine("Connection closed with error: {0}", e);
  
              cts.Cancel();
              return Task.CompletedTask;
          };
  
          connection.On("broadcastMessage", async () =&gt;
          {
  
  
          });
  
          while (true)
          {
              Thread.Sleep(2000);
  
              await connection.SendAsync("send", "alex", "hello");
  
          }
      }
  </code></pre>
  
  <p>All the code is working but on the console application i am receiving this exception:</p>
  
  <pre><code> Microsoft.AspNetCore.Sockets.Client.HttpConnection[19]
        09/17/2017 13:47:17: Connection Id 40da6d4b-9c47-4831-802f-628bbb172e10: An exception was thrown from the 'Received' event handler.
  System.FormatException: Target method expects 0 arguments(s) but invocation has 2 argument(s).
     at Microsoft.AspNetCore.SignalR.Internal.Protocol.MessagePackHubProtocol.CreateInvocationMessage(Unpacker unpacker, IInvocationBinder binder)
     at Microsoft.AspNetCore.SignalR.Internal.Protocol.MessagePackHubProtocol.TryParseMessages(ReadOnlyBuffer`1 input, IInvocationBinder binder, IList`1&amp; messages)
     at Microsoft.AspNetCore.SignalR.Internal.HubProtocolReaderWriter.ReadMessages(Byte[] input, IInvocationBinder binder, IList`1&amp; messages)
     at Microsoft.AspNetCore.SignalR.Client.HubConnection.&lt;OnDataReceivedAsync&gt;d__31.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNetCore.Sockets.Client.HttpConnection.&lt;&gt;c__DisplayClass49_0.&lt;&lt;ReceiveAsync&gt;b__0&gt;d.MoveNext()
  </code></pre>