SignalR Hub Connection Error

对着背影说爱祢 提交于 2019-12-11 21:21:47

问题


I've just started using a bit of SignalR and am trying to set it up so a windows service can send messages to a web page.

I have the hub all setup and this seems to work fine within the website.

Namespace SignalR
    Public Class SignalRHub
        Inherits Hub

        Public Sub Send(name As String, message As String)

            Clients.All.broadcastMessage(name, message)

        End Sub
     End Class
End Namespace

However I can't get my windows service to connect to the hub in any shape or form.

The code below correctly gets an auth token via the webservice and then makes the hub connection. However the hub connection always comes back disconnected and then the hubConnection start always throws the error "Unexpected character encountered while parsing value: . Path '', line 0, position 0."

I've tried monitoring in fiddler and nothing appears to show up for any kind of attempt at hitting the SignalR api. The hubs page is up and accessible at

http://localhost:56731/signalr/hubs

Anyone know what I'm doing wrong?

       protected override void OnStart(string[] args) {

            Debugger.Launch();

            WriteToLog("Service Started");

            try {

                String url = "http://localhost:56731/";                

                var wsAuth2 = new wsAuth.Authentication();
                string authToken = wsAuth2.Authenticate("username", "password");

                var hubConnection = new HubConnection(url,
                                   new Dictionary<string, string>
                                   {
                                       { "token", authToken }
                                   });                                          

                IHubProxy signalRServiceProxy = hubConnection.CreateHubProxy("SignalRHub");                

                hubConnection.Start().Wait();


                signalRServiceProxy.Invoke("Send", "Hello Billy!").Wait();
            }
            catch (Exception ex) {
                var error = ex.GetError();
            }                    
        }

Thanks.


回答1:


This looks like your issue here- the solution may be to turn off Forms authentication, or to check that the method signature matches between client and server:

https://github.com/SignalR/SignalR/issues/1779



来源:https://stackoverflow.com/questions/22808057/signalr-hub-connection-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!