SignalR Client error when trying to connect to server with connection.Start ()

I am using SignalR example from ASP.NET site:

http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-server-broadcast-with-signalr-20

      

The server is working fine and the JavaScript clients are working as they should and communicating with each other. JavaScript server and client are running on IIS.

The JavaScript client is located at:

http://192.168.1.5:8080/RTStreamer/SignalR.Sample/StockTicker.html

      

Now I'm trying to make a C # Windows Forms client, but with no success:

private void Form1_Load(object sender, EventArgs e)
{
    var connection = new HubConnection("http://192.168.1.5:8080/RTStreamer/signalr");
    IHubProxy proxy = connection.CreateHubProxy("StockTickerHub");

    try
    {
        connection.Start().Wait();
        var stocks = proxy.Invoke<IEnumerable<Stock>>("GetAllStocks").Result;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}

      

I am getting this error when trying to connect .Start ():

System.AggregateException: One or more errors occurred. ---> Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Transfer-Encoding: chunked
  Cache-Control: private
  Date: Tue, 12 Aug 2014 13:46:31 GMT
  Server: Microsoft-IIS/8.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Content-Type: text/html; charset=utf-8
}
   at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass2.<Get>b__1(HttpResponseMessage responseMessage)
   at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass19`2.<Then>b__17(Task`1 t)
   at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3a.<RunTask>b__39(Task`1 t)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at TraderClient.Form1.Form1_Load(Object sender, EventArgs e) in c:\Ark\Form1.cs:line 31
---> (Inner Exception #0) Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Transfer-Encoding: chunked
  Cache-Control: private
  Date: Tue, 12 Aug 2014 13:46:31 GMT
  Server: Microsoft-IIS/8.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Content-Type: text/html; charset=utf-8
}
   at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass2.<Get>b__1(HttpResponseMessage responseMessage)
   at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass19`2.<Then>b__17(Task`1 t)
   at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3a.<RunTask>b__39(Task`1 t)<---

      

This is the hub code:

namespace Microsoft.AspNet.SignalR.StockTicker
{
    [HubName("stockTicker")]
    public class StockTickerHub : Hub
    {
        private readonly StockTicker _stockTicker;

        public StockTickerHub()
            : this(StockTicker.Instance)
        {

        }

        public StockTickerHub(StockTicker stockTicker)
        {
            _stockTicker = stockTicker;
        }

        public IEnumerable<StockQuote> GetAllStocks()
        {
            return _stockTicker.GetAllStocks();
        }

        ...

    }
}

      

+3


source to share


1 answer


Setting up the project exactly as per the linked article, the .NET client that works for me has the following code:

var connection = new HubConnection("http://localhost:65069/");
IHubProxy proxy = connection.CreateHubProxy("stockTickerMini");

try
{
    connection.Start().Wait();
    var stocks = proxy.Invoke<IEnumerable<Stock>>("GetAllStocks").Result;
}
...

      

In my example, the page StockTicker.html

is in http://localhost:65069/StockTicker.html

and the hub name stockTickerMini

matches the attribute.



In your case, the values โ€‹โ€‹below should be correct:

var connection = new HubConnection("http://192.168.1.5:8080/RTStreamer");
IHubProxy proxy = connection.CreateHubProxy("stockTicker");

      

+3


source







All Articles