Jacob Jacob - 9 days ago 5
C# Question

Passing object parameter to hub method

Although there are many questions like that on the web, I haven't found a right one that solves my issue:

I have a SignalR hub method:

public ClientResponses ProcessRequest(ClientRequest request) {...}


This method gets
ClientRequest
object as parameter:

[Serializable]
public class ClientRequest : BaseClientRequest
{
[JsonProperty("input")]
public string Input { get; set; }
}


I call this method from the client like that:

var input = new Input(message);
var jsonInput = JSON.stringify(input);
hubProxy.server.processRequest(jsonInput);


When sending, their values are:

enter image description here

But the method at the server side (
ProcessRequest
) never called.

When I change this method to get a string type parameter and sent a pure string from the client it works properly.

Answer

The short answer is that the line :

var jsonInput = JSON.stringify(input); 

isn't needed as you can send straight javascript objects to SignalR.