[c# SignalR] Calling a hub method with optional arguments without providing it from the JS client?

[c# SignalR] Calling a hub method with optional arguments without providing it from the JS client?

BlushyFaceBlushyFace Member, Administrator, Moderator Posts: 9
edited July 9 in Programming #1

Does anyone know how to invoke a hub method with optional arguments from a JavaScript client ?

In this case I'm invoking a hub method that returns a list of objects but sometimes I want more or less so I wrote the hub method that has an optional argument to do so. The issue is that I'm not sure how to invoke the hub method without using any arguments in my JS client calls as it doesn't seem to hit the hub method..

Example

I could call the GetSomething method in the hub like this in the JS client -> proxy.invoke('GetSomething', 10); to get 10 objects, if I want to get 5 objects I could do either proxy.invoke('GetDonations', 5); OR proxy.invoke('GetDonations'); as the default argument is 5 but when invoking without any arguments instead of calling the method with the optional argument (ideally) it calls the overloaded method with no arguments that in turns calls the method with the optional argument, see why it's ugly?

Ideally the method without any arguments would be made redundant but by doing so the JS client can't invoke the method without passing any arguments so the additional method is required for the JS client function to work..

If anyone has a more elegant solution let me know.

Post edited by BlushyFace on

Comments

  • BlushyFaceBlushyFace Member, Administrator, Moderator Posts: 9
    edited July 9 #2

    After discussing it with people it seems that it's likely a limitation in SignalR as it doesn't support invoking hub methods that have optional args. I already fixed this by adding the same method without any args (see post above) and set the default value there but yeah, it's not really elegant. If anyone does have a better solution let me know!

Sign In or Register to comment.