0

Suppose I have a SignalR client-server scenario and I want to manually activate a method on the server and also have some feedback from it. Suppose my javascript code is:

myHub.server.doStuff()

and my C# code is:

public void DoStuff()
{
    // some stuff gets done and it can be successful or not.
}

If I was to do an AJAX request I would be able to get info on the result of the action from the http response. Is there a possibility to have this behavior in SignalR, something like this?

myHub.server.doStuff(function callback(response) { // handle response.. })

The most I could think of was having an additional method on the client which would get called from the server when it knows the result, something like:

myHub.client.doStuffCallback = function (result) { // interpret the result }

However this method does not seem secure, plus I would have to have a very safe mechanism of correlating "responses" with "requests". Can SignalR be used in a way similar to what I am describing?

Vee6
  • 1,527
  • 3
  • 21
  • 40
  • 1
    SignalR doesn't guarantee message delivery. Since SignalR doesn't block when you call client methods, you can invoke client methods very quickly as you've discovered. Unfortunately, the client might not always be ready to receive messages immediately once you send them, so SignalR has to buffer messages. http://stackoverflow.com/a/22207631/3936473 – Florin Secal May 08 '16 at 21:01
  • Possible duplicate of [How to do guaranteed message delivery with SignalR?](http://stackoverflow.com/questions/22197129/how-to-do-guaranteed-message-delivery-with-signalr) – Florin Secal May 08 '16 at 21:05
  • Makes sense, thanks. – Vee6 May 09 '16 at 07:56

0 Answers0