Categories: RIA, Silverlight, SocialBus, WCF Posted by mheydt on 12/13/2009 10:18 PM | Comments (4)
In part 2 I showed how to create a domain service and get the code generated for that service (heck that was automatic).  In this post I'll show how to call that service from Silverlight.

In the the first post I added a reference to the Silverlight project to the Silverlight.RIA project, which will allow the Silverlight application to use those classes.  I modify the MainPage.XAML to have a TextBox named 'result' and modify the MainPage.XAML.cs file to be as follows to call the service and display the result:



What's going on here?  We'll, there is a whole new syntax to these calls, which I will explain briefly. 

On lines 14 and 15 I add two namespaces as they are needed for the InvokeOperation (System.Windows.Ria), and the SocialBus.RIA.Web is the namespace in our RIA web project that contains the domain service.

The domain service we created is implemented by the SocialBusDomainContext class.  It has a bunch of methods for managing entities, as well as the method I added to the class, 'Add'.  To call the service, I create a new instance of this class, and call the 'Add' method.  As is the case in Silverlight, all calls are asynchronous, so to capture the result a delegate is assigned to the method calls return value's (which is an InvokeOperation object) Completed event handler.  I choose to use the lamba syntax for this, and the method is actually passed the InvokeOperation object and an EventArgs object.  I cast the 's' parameter to InvokeOperation<double> (the generic is important), get the return Value, convert it to a string and assign it to the text box on the UI.

Sure, there is a lot more detail that can be covered here, such as error/exception handling and such, but this show the basics of calling the service and using the result.  In the next post, I'll show how to create a POCO and pass it to the client.

Comments

trackback
42 Spikes on 1/26/2010 11:59 AM Using WCF RIA Services with your POCO - Links

Using WCF RIA Services with your POCO - Links
Bobby
Bobby United States on 3/3/2010 9:59 AM Hey there, are you having issues with your hosting? I needed to refresh the page about four times to your site load. You might want to change hosts, or could the problem be from me?

-Bobby
nokia review
nokia review United States on 3/7/2010 1:35 AM Looking forward for more such stuff. Loved your style of providing the information and the nature of the content.
seo tools
seo tools Slovenia on 3/9/2010 6:16 AM Although I don't agree with all you said, I must confess I do love your style of writing.

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading