Silverlight: No more synchronous web request...

Apparently, one big thing was removed from Silverlight between Alpha and the current Beta 1: It's not possible to make synchronous web requests anymore.

I must be honest: I have always been recommending against synchronous requests from a web browser to a web server. But it was nice to have the possibility to do it. I can think of a couple of scenarios where it makes sense. What I don't quite understand is why they removed it. The reason given yesterday (that it blocks the UI thread) is not really a good one, considering how easy it is to start a worker thread and to send the request from there... then again, one can argue that if you do start a worker thread anyway, you'd just as easily send an asynchronous request.

Print | posted on Thursday, March 6, 2008 4:58 AM

Feedback

# re: Silverlight: No more synchronous web request...

left by Laurent at 3/6/2008 10:26 AM Gravatar
I totally agree that blocking the UI thread is bad practice (I say so in my post), but starting a worker thread and making a synch request from there is really really easy. Then again, making a worker thread do the synch request or make an asynch request, I can we can argue that it's pretty much the same complexity of code.

# re: Silverlight: No more synchronous web request...

left by Ol at 3/25/2008 6:30 PM Gravatar
Yeah, but spinning up a worker thread that calls one service and, depending on the result, calls another service (and another...) is way easier than using async chaining. Not to mention that the code is far more maintainable. :-)

IMO, Web service calls are like (expensive) method calls and we should have the option of calling them synchronously (at least from background threads).

# re: Silverlight: No more synchronous web request...

left by Andy at 6/7/2008 9:12 AM Gravatar
My problem with the lack of synch is the .NET GIS solution i want to build my solution on does not support asynch.


# re: Silverlight: No more synchronous web request...

left by Laurent at 6/7/2008 10:25 AM Gravatar
Maybe you can wrap it server-side and expose a web (or WCF) service that could be asynchronous?

# re: Silverlight: No more synchronous web request...

left by bseddon at 1/1/2009 8:23 PM Gravatar
Surely this is not an issue of whether one approach or another is "better". Its about the Microsoft developers removing Silverlight developer choice about the way an application is created. I can understand that Microsoft do not want arbitrary developers blocking the browser. However forcing a programming model on developers to address a short-coming in the design of the browser (I mean IE here because it's COM-based and the UI is bound to one thread) seems a poor choice.

# re: Silverlight: No more synchronous web request...

left by Laurent at 1/1/2009 10:44 PM Gravatar
Hi,

Actually you are mistaken. First Silverlight runs in a plug-in, and is fully multi threaded. Yes the UI is bound to one thread (nothing to do with COM here, it's an architecture decision, which is actually also the case in Windows Presentation Foundation, a desktop technology), but nothing prevents you to start background threads. It's in fact the same threading model as in WPF, so if you're familiar with that, you will feel at home in Silverlight.

Second, interestingly, the reason why only asynchronous requests are supported is because of other browsers. To allow Silverlight to run on multiple platforms, the team had to choose the least common denominator for the networking layer. Asynchronous it is...

I want to point you on Peter Bromberg's thoughts on the topic:
http://petesbloggerama.blogspot.com/2008/07/omg-silverlight-asynchronous-is-evil.html

I think it says it all ;)

Happy coding,
Laurent

# re: Silverlight: No more synchronous web request...

left by Daniel Vaughan at 6/23/2009 4:47 PM Gravatar
Hi Laurent,

I realise it has been a while since you posted this entry, and I hope you’ll forgive a fellow Disciple if I chime in now to say that I did some experimentation and found that, in fact, synchronous calls are possible.
I wrote an article on it last year. http://www.codeproject.com/KB/silverlight/SynchronousSilverlight.aspx

All the best,
Daniel

# re: Silverlight: No more synchronous web request...

left by Laurent at 6/26/2009 4:36 AM Gravatar
Hey Daniel,

If I recall correctly, I was at MIX08 when they announced that SL2 would not support synchronous calls anymore, and I reported this news as is. Happy to see that you dug a little more ;)

Good job,
Comments have been closed on this topic.