SignalR .NET Client - Unexpected character encountered while parsing value

Viewed 5800

I'm trying to set up a .NET client to send messages to my SignalR hub from my service layer. I'm following this guide: http://www.asp.net/signalr/overview/signalr-20/hubs-api/hubs-api-guide-net-client#callserver

This is what I have:

        _hubConnection = new HubConnection(_baseUrl); // "http://localhost:3806"
        _hubProxy = _hubConnection.CreateHubProxy("AppHub");
        _hubConnection.Start().Wait();

The hub lives inside of the same project - it's an MVC application with forms authentication.

I can never get past the .Wait() call, it always errors out with the following:

Message=Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
       Source=Newtonsoft.Json

More trace:

at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at Microsoft.AspNet.SignalR.Client.Transports.TransportHelper.b__1(String raw) at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass192.<Then>b__17(Task1 t) at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners2.<>c__DisplayClass3a.<RunTask>b__39(Task1 t)

I have AppHub:

public class AppHub : Hub { .. }

What am I doing wrong?

4 Answers

When I was getting this message, it was because when pointing to the URL of the server I used HTTP instead of HTTPS:

using (var hubConnection = new HubConnection("http://someurl.com"))
{
    var hubProxy = hubConnection.CreateHubProxy("smsHub");
    await hubConnection.Start();
    await hubProxy.Invoke(....);
}

Pointing to the HTTPS url resolved the issue.

Related