Sony Arouje

a programmer's log

Archive for October 16th, 2010

Image uploading & Retrieving – Silverlight and WCF

with 9 comments

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

image

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

Written by Sony Arouje

October 16, 2010 at 4:04 am

%d bloggers like this: