The client initiating long polling, calls a method on server and passes in an instance of AsyncCallback which contains the callback delegate which will be invoked when server asynchronously gets back to the client.
Now my understanding on this is limited but it appears that in BasicHttp WCF the AsyncCallback parameter is serialised and sent to server which then de-serialises it, caches it and ultimately invokes it to “get back” to the client.
Firstly, is the above explanation correct? Secondly, how does the AsyncCallback invoked on a client all the way across network?
The connection is kept open so the server responds over the existing connection, including the callback handler name in the response.
The client understands the format of the message and can then invoke the appropriate local method (based on the callback handler) with the data from the server response.
I usually prefer not to quote Wikipedia but in this instance, it’s not a bad explanation of long polling…
Clarification
AsyncCallback‘s methods on the server)This is similar to the way JSONP works (The callback part, not long polling), if you’re familiar with that? Essentially, the Callback handle is only passed to the server so that it can be sent back with the response and allow the client to call the correct method.
There are additional checks going on under the hood to make sure that only the intended methods are called and a malicious server can’t just execute any method it chooses in client code.