c# - Signalr net client On event generic type parameter -


i want client method handlemessage work types implements imessage, did follows, handlemessage method has never hit. should use concrete type parameter in hub.on<t> events?

signalr client

hub = connection.createhubproxy("test"); hub.on<imessage>("receivemessage", (payload) => handlemessage(payload)); await connection.start(); 

signalr server

public static async task broadcast(payload payload) {     try     {         var user = userhandler.userlist.find(x => x.userid == payload.customerid.tostring());         if (user != null)         {             await sendrelatedpayload(payload, user);         }     }     catch (exception ex)     {     } } private static async task sendrelatedpayload(payload payload, userconnection user) {     string[] data = payload.messagecontent.split('|');      switch (payload.messagetype)     {         case (short)messagetype.order:              imessage order = new order             {                 customerid = data[0],                 orderid = data[1],                 orderstatus = data[2],             };             await context.clients.client(user.connectionid).receivemessage(order);              break;         case (short)messagetype.accrual:              imessage accrual = new accrual             {                 customerid = data[0],                 orderid = data[1],                 nominal = data[2],                 price = data[3],             };             await context.clients.client(user.connectionid).receivemessage(accrual);              break;     } } 

types

public interface imessage {     string customerid { get; set; } }  public class accrual : imessage {     public string orderid { get; set; }     public string price { get; set; }     public string nominal { get; set; }     public string customerid { get; set; } }  public class order : imessage {     public string orderid { get; set; }     public string orderstatus { get; set; }     public string customerid { get; set; } } 

i think signalr supports concrete type method handlers, need add specific events each type.

thanks.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -