SignalR send object - newbie

With an R signal, if you are trying to send an object, what is the syntax for passing the model?

private async void FormLoaded(object sender, RoutedEventArgs e)
{
    //Connection stuff...
    Proxy.On("sendHello", () => OnSendDataConnection(ModelBuilder()));
}

private void OnSendDataConnection(ConnectionModel model)
{
    Dispatcher.Invoke(DispatcherPriority.Normal,model?????)
    this.Dispatcher.Invoke((Action)(LoadW));
}
+4
source share
1 answer

Looking at the question (text, not code), I understand that you are trying to send the Complex object to the JS side and use it there? It is right?

In this case, the solution should be simple:

From ASP.NET.SignalR :

You can specify the type and parameters of the return, including complex types and arrays, as in any C # method. Any data that you receive in the parameters or return to the caller is transferred between the client and server using JSON, and SignalR processes the binding of complex objects and arrays of objects automatically .

C # example:

    public void SendMessage(string name, string message)
    {
        Clients.All.addContosoChatMessageToPage(new ContosoChatMessage() { UserName = name, Message = message });
    }

JS:

    var contosoChatHubProxy = $.connection.contosoChatHub;
    contosoChatHubProxy.client.addMessageToPage = function (message) {
        console.log(message.UserName + ' ' + message.Message);
    });

ContosoChatMessage:

   public class ContosoChatMessage
   {
       public string UserName { get; set; }
       public string Message { get; set; }
   }

( ...)

, , JS "" "model.XY", XY .

, .

+2

All Articles