WCF service call Async

Topics: Prism v4 - Silverlight 4
Feb 14, 2011 at 8:51 AM

Hi,

I am new to this thread and Prism, so please bare with me if this is an elementy level question. I am trying to get the WCF Service working with the Silverlight chart control. It is using MVVM. The data is comming out of the WCF database async. The problem (or it seems like) that on the viewmodel to view bind and then vm load the Property which is binding the datacontext of the ChartControl is not getting the collection in time!. I mean it seems to get the data sometime later (being Async call).

I am not sure how to handle this senario. I saw an example in the Prism QuickStarts > View-Switching Navigation. Where in infrastructure it has its own Async mechanism. I have tried to use that example as well as simple senario but it does not seems work. Any idea?

Thanks,

Preyash

Developer
Feb 14, 2011 at 3:40 PM

Hi Preyash,

An async method from a WCF service should have a completed event (for example, if the method is called GetDataAsync, the event would be called GetDataCompleted). You could subscribe to that event and update a property in your ViewModel in the handler (if the method returns data, you should have a Result property in your event args).

Note that your ViewModel must implement INotifyCollectionChanged in order for the changes in the collection to be propagated to the view.

You might find the following MSDN articles useful:

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Feb 15, 2011 at 4:39 AM

Dear GuidoMaliandi,

Thanks for the quick reply. That was a very good detailed explanation and it solved the problem.

Here's what I did (just for the guys who has similar problem)

I have inherited NotificationObject (from Prism) in my viewmodel.

The NotificationObject has INotifyCollectionChanged implemented so we dont have to worry about it!

and then on Collection's Setter 

this.RaisePropertyChanged(() => this.Books);

Done.

Thanks,

Preyash



Developer
Feb 24, 2011 at 5:12 PM

Hi Preyash,

Thank you for sharing your insight with the rest of the community, as other users facing similar doubts might benefit from your information.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi