Pregunta

I've been playing around with SignalR for a few days and I have to say that it's an absolutely phenomenal library. I've managed to get a few things working with it and was astounded at the simplicity, but I recently ran into a small problem.

I'm unable to call a Hub method from JavaScript in the browser. The request returns a 500 error code, and when I look at the error page source, I see this:

[ArgumentNullException: Value cannot be null.
Parameter name: s]
System.IO.StringReader..ctor(String s) +10207225
Newtonsoft.Json.Linq.JObject.Parse(String json) +74
SignalR.Hubs.HubRequestParser.Parse(String data) +78
SignalR.Hubs.HubDispatcher.OnReceivedAsync(IRequest request, String connectionId,  String data) +266
SignalR.<>c__DisplayClass6.<ProcessRequestAsync>b__4(String data) +84
SignalR.Transports.ForeverTransport.ProcessSendRequest() +159
SignalR.Transports.ForeverTransport.ProcessRequestCore(ITransportConnection connection)  +149
SignalR.Transports.ForeverTransport.ProcessRequest(ITransportConnection connection) +42
SignalR.PersistentConnection.ProcessRequestAsync(HostContext context) +1087
SignalR.Hubs.HubDispatcher.ProcessRequestAsync(HostContext context) +251
SignalR.Hosting.AspNet.AspNetHandler.ProcessRequestAsync(HttpContextBase context) +656
SignalR.Hosting.AspNet.HttpTaskAsyncHandler.System.Web.IHttpAsyncHandler.BeginProcessReques t(HttpContext context, AsyncCallback cb, Object extraData) +143
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  +9479007
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&  completedSynchronously) +178

My server-side code is:

public class SourceHub : Hub
{
    public void RegisterSource(string source)
    {
        Groups.Add(Context.ConnectionId, source);
    }
}

and on the client-side I have:

var SourceHub = $.connection.sourceHub;
$.connection.hub.start().done(function () {
    SourceHub.registerSource("test");
});

I've been digging for a while, but I just can't find the source of the problem... could someone please help me out?

¿Fue útil?

Solución

Preface: I'm on edobry's team for this project, and I'm the backend guy, so this foray into frontend was new and fascinating to me.

So, after some careful dissection of the code as I stepped through the project, it turns out that the POST data in the request variable was coming up empty. The data was getting sent properly up to the $.ajax call, but never arriving at the server. Some more hunting and I had uncovered something suspicious that edobry and I were then able to discern what was happening.

We're using Ajax for other parts of the page, and the ajax method is called several times, so we had factored out some settings we set on every method call into $.ajaxSetup. One of these was dataType getting set to "text", and contentType to "application/json". It seems that signalR is not overriding global ajax settings properly. I'm not sure if this is a bug or intended behavior, but it should be documented better if that's the case (and if it is, feel free to call us dumb. :))

Otros consejos

Your method is called RegisterSource and you call registerSources instead of registerSource in javascript.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top