Faking synchronous web service calls in Silverlight

I ran into a small but thought-provoking problem in my sample Silverlight database application. I wanted to call a web service, and only call a second web service if the first was successful. The problem is that all web service calls are asynchronous, so you cannot do this with a simple if statement. The quick fix I used was to store my intended operation in a PendingOperation variable. When the first web service completes, it checks for a pending operation. If the first call succeeds and finds a pending operation, it calls the second web service to complete it.

My workaround is OK, but it got me thinking about the best way of doing this. What if you had a sequence of web services to call, and wanted to check for the success of each one before proceeding to the next? I discussed this on the Silverlight forums and was directed to this article by Daniel Vaughan which describes how to do this in a background thread. I haven’t tried his code yet; but it strikes me that this could be useful; I’d like to see Microsoft build something like it into the core framework. Since all the calls take place on a background thread, there is no danger of locking up the user interface.

If RIA programming is as important as some suggest we will have to get used to this kind of problem.

VN:F [1.9.18_1163]
Rate this post
Rating: 0.0/10 (0 votes cast)

Related posts:

  1. iPhone 4 Antenna: Apple wrongly calls it a software problem – but it is easily fixed with a case
  2. Testing a web service with IIS 7 on Vista
  3. Silverlight in Microsoft products – Silverlight the new Windows runtime, HTML 5 the new Silverlight?
  4. Traditional IT is a scam, says Salesforce.com CEO Marc Benioff, introducing Service Cloud 2
  5. Memory leak bug in useless NVIDIA Windows service

2 comments to Faking synchronous web service calls in Silverlight