Image uploading & Retrieving – Silverlight and WCF
In several forums I saw people asking about how we can upload Images or files to server using silverlight. So I thought of writing one to demonstrate how we can achieve it. I become a big fan of caliburn micro and I used it in this app as well.
In this demo app I demonstrating both approach of accessing WCF service – Proxy less and Proxy approach. I personally like Proxy less approach so I cannot avoid it here also.
Let’s go through my solution structure
Repository: This project contains entities and persistence classes. I made it as simple as possible in this demo, so all the persistence related stuff is in the same project.
WCFService: Project contains the service implementation
WCFService.Interfaces: project contains the service contracts.
WCFHost: Project host the WCF service.
In Silverlight folder I have a Project called ServiceLinkProject, that is a project that has link to entity files. It is used for Proxy less WCF communication. In this demo I used my generic repository mentioned in my previous post.
There is nothing much to explain here except the valueconverter I used in the xaml page. I save and retrieve images as byte arrays. But silverlight’s Image control will not be able to render byte arrays. So wrote a Converter inherited from IValueConverter. Let’s see how am using it.
First I created an instance of the converter.
<navigation:Page.Resources> <converter:ByteToImageConverter x:Name="binaryConverter"/> </navigation:Page.Resources>
Now use this converter while binding the byte[] to image.
<Image x:Name="thumbNail" Width="100" Height="100" VerticalAlignment="Center" Source="{Binding ImageInBytes,Converter={StaticResource binaryConverter}}"></Image>
I think this project doesn’t requires much explanation. If any one has any questions then am happy to help you out.
Download Source code
[…] This post was mentioned on Twitter by Larry King, sony arouje. sony arouje said: Image uploading & Retrieving – Silverlight and WCF: http://wp.me/p12zd9-1e […]
Tweets that mention Image uploading & Retrieving – Silverlight and WCF « Sony Arouje Blog -- Topsy.com
October 16, 2010 at 5:05 am
[…] I wrote to upload images using Silverlight and WCF, you can get more details of that app from my blog. I will rewrite only the part where I make async calls to server to get images from WCF service. […]
Making Async calls in Silverlight using Reactive Extension (Rx) | Sony Arouje Blog
October 31, 2010 at 12:10 pm
Hi. I could not compile the source code. I’m getting all kinds of errors. Is there anything missing from the source code folder to compile in Visual Studio 2010? Thanks!
Marcus McElhaney
February 18, 2011 at 12:22 am
Hi Marcus,
I am not sure what kind of errors you are getting. You need to run WCFServiceHost project first, then start Image_Fetch_DB.Web project. If still not working post the errors here.
sonyarouje
February 18, 2011 at 11:15 am
hi to all sonyarouje.comers this is my first post and thought i would say hi –
speak soon
garry moore
garrymoore
November 26, 2011 at 10:04 pm
It worked, thanks a lot.
Anonymous
September 29, 2012 at 8:41 am
good to hear that. Thanks for leaving your comments.
Sony Arouje
September 29, 2012 at 10:55 am
unable to download the sample can you send the download link
ramesh
October 7, 2014 at 11:34 pm
Hi Ramesh,
Updated the source code link, link got changed when MS moved to OneDrive.
Regards,
Sony Arouje
Sony Arouje
October 8, 2014 at 2:14 am