Last post Apr 14, 2015 08:30 PM by leandrods
Mar 11, 2014 12:13 PM|andyste|LINK
I'm using SignalR with a .Net client. The server will be used to execute numerous "commands", but I would rather not implement a separate hub method for each command, e.g. LightOn, LightOff, VolumeUp, VolumeDown, etc.... Instead it would be nice if I could
expose a single hub method such as:-
public void ExecuteCommand(CommandBase command)
but this approach doesn't work. If a client sends it a subclass of CommandBase, the server just gets a CommandBase object. Is there another solution? I don't want to have to go back to WCF!
Mar 17, 2014 04:26 AM|Ruchira|LINK
If a client sends it a subclass of CommandBase, the server just gets a CommandBase object. Is there another solution?
How do you define the object? You should define and pass the object as show in the below link
Please 'Mark as Answer' if this post helps you
Mar 17, 2014 04:52 AM|andyste|LINK
Thanks for the reply. I know how to pass objects between client and server. The problem is that SignalR has some restrictions when using objects as parameters, which I'm guessing has something to do with the serialization framework.
For starters, it doesn't let you use an interface or abstract class as a hub method parameter (SignalR throws an exception). So instead I tried using a non-abstract base class as a method parameter (the "CommandBase" class, as mentioned above). When a client
invokes the hub method and passes it an object that inherits from CommandBase (e.g. "TurnLightOnCommand"), what arrives at the hub method is a "CommandBase" object, and not a "TurnLightOnCommand" object. Like I say, I think it's the serialization
process causing the problem.
Apr 14, 2015 08:30 PM|leandrods|LINK
Hello. Were you able to resolve this problem? I'm in the same situation