Question

The sample here and documentation here seem to show how to do this with the JavaScript SignalR libray, I am trying on my own to figure this out using a console client application to GetAllStocks without any success.

Here is my client console app code just concentrating on the GetAllStocks not the update at this point :


using System;
using System.Collections;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client.Hubs;

namespace StockTicker.Client
{
    class Program
    {

       static void Main(string[] args)
        {
            RunAsync().Wait();
        }

       private static async Task RunAsync()
        {

            var hubConnection = new HubConnection("http://localhost:8080/");
            IHubProxy stockTickerMini= hubConnection.CreateHubProxy("stockTickerMini");


             stockTickerMini.On("GetAllStocks", stocks =>
                {
                    foreach (var stock in stocks)
                    { Console.WriteLine(stock.Symbol + ":" + stock.Price); }
                });


              await hubConnection.Start();

           }
    }
 }


Was it helpful?

Solution

The code you have is incorrect. GetAllStocks is a method that the client can invoke on the server (e.g. it's something the server exposes). You can do:

var stocks = await stockTickerMini.Invoke<IEnumerable<Stock>>("GetAllStocks");

If you want to get called back when stocks are being updated then you need to look at what the server side is calling back on the clients object:

Which is detailed right here:

http://www.asp.net/signalr/overview/hubs-api/hubs-api-guide-net-client#establishconnection

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top