{"id":1381,"date":"2009-04-28T20:55:48","date_gmt":"2009-04-28T19:55:48","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/1381-faking-synchronous-web-service-calls-in-silverlight.html"},"modified":"2009-04-28T20:55:48","modified_gmt":"2009-04-28T19:55:48","slug":"faking-synchronous-web-service-calls-in-silverlight","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/1381-faking-synchronous-web-service-calls-in-silverlight.html","title":{"rendered":"Faking synchronous web service calls in Silverlight"},"content":{"rendered":"<p>I ran into a small but thought-provoking problem in my sample <a href=\"http:\/\/www.itwriting.com\/silverlightdata\/Default.aspx\" target=\"_blank\">Silverlight database application<\/a>. 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.<\/p>\n<p>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 <a title=\"SynchronousSilverlight.aspx\" href=\"http:\/\/www.codeproject.com\/KB\/silverlight\/SynchronousSilverlight.aspx\">article by Daniel Vaughan<\/a> which describes how to do this in a background thread. I haven\u2019t tried his code yet; but it strikes me that this could be useful; I\u2019d 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. <\/p>\n<p>If RIA programming is as important as <a href=\"http:\/\/asserttrue.blogspot.com\/2009\/04\/how-ria-wars-will-affect-future-of.html\">some suggest<\/a> we will have to get used to this kind of problem.<\/p>\n<div style=\"padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px\" id=\"scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ce116dd0-add6-4c05-b6b6-a991e09a71ba\" class=\"wlWriterEditableSmartContent\">Technorati Tags: <a href=\"http:\/\/technorati.com\/tags\/silverlight\" rel=\"tag\">silverlight<\/a>,<a href=\"http:\/\/technorati.com\/tags\/web+services\" rel=\"tag\">web services<\/a>,<a href=\"http:\/\/technorati.com\/tags\/asynchronous\" rel=\"tag\">asynchronous<\/a>,<a href=\"http:\/\/technorati.com\/tags\/programming\" rel=\"tag\">programming<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/1381-faking-synchronous-web-service-calls-in-silverlight.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Faking synchronous web service calls in Silverlight<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77,96],"tags":[],"class_list":["post-1381","post","type-post","status-publish","format-standard","hentry","category-silverlight","category-web-authoring"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=1381"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/1381\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=1381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=1381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=1381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}