Jacob
Jacob

Reputation: 3698

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.

Upvotes: 1

Views: 1114

Answers (1)

Steve
Steve

Reputation: 2997

The short answer is that the line :

var jsonInput = JSON.stringify(input); 

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

Upvotes: 2

Related Questions