views:

619

answers:

2

I'm fetching data (images, 200-400kb) from WCF service to Silverlight client and notice that the Silverlight stops for a fraction of second every time such message arrive. It's not really serious but the animation stops for a while and the whole user experience is ruined.

Question time:

1) Do you think it would be beneficial to use WebClient instead?

2) Does "normal" WCF client in Silverlight (by "normal" I mean event-driven scenario) deserialize data contracts in main (calling) thread or in the background?

3) Do you think overhead necessary to deserialized binary object from data contract in XML (+ bigger data size thanks to Base64 XML encoding) is bigger/smaller than additional round trip to the server (in which case data contract would only contain URL to the image and than I could use WebClient to get it - hence another trip)?

4) Is it possible to create Image from byte[] array in the background thread (not UI thread)?

Any help, ideas, suggestions much appreciated.

Thanks,

Karol

PS: I cannot use DeepZoom because business requirements don't really match DeepZoom scenarios.

A: 

WCF's main purpose is to provide a means of getting structured data from one place to another. I don't think images is what it is meant for. I think that using WebClient would probably work a lot better and faster. Also, you might want to do a little more looking into whether or not there is another solution specifically for downloading resource files from the server using Silverlight.


UPDATE: Actually if you are just using a regular Image control you can just set (or change) the Source property to a new Bitmap - this will automatically trigger the download of the image from the server location:

img.Source = new BitmapImage(new Uri("http://the.image.url/image.jpg"));

Then, you can programatically add the Image control into your Silverlight document.

NathanD
A: 

You could also just use a HTTP Handler class on the server side that returns the Image. I'm assuming that you chose to use a WCF service because there's some logic on the server side that determines which image should be returned. Using an HTTP Handler you would have the option to perform that logic on the server side and return the image in one round-trip.

Have the Handler call your WCF Service to get the URL, retrieve the image and return it in the HTTP response stream. If you set the MIME type properly, the client (in this case Silverlight) won't know the difference.

Steve
Thanks Steve, at the end I've created second end point with REST protocol, so I can return image as binary from the very same service and consume it in Silverlight via WebClient.
Karol Kolenda
Update: I've done some performance testing. If anyone is interested: raw binary via REST is 2.5 faster than the same data serialized as DataContract.
Karol Kolenda