Search This Blog

Friday, February 8, 2013

Silverlight call simple get (REST/HTTP) and receive an image

This is the simplest method to receive an image from http server - we receive a stream with the message.


var wc = new System.Net.WebClient();
var applicationHostSource = Application.Current.Host.Source;
var request = "http://" + applicationHostSource.Host + ":" + applicationHostSource.Port +"/" + "Image.png";
wc.OpenReadCompleted += (sender, downloadStreamCompletedEventArgs) =>
{
var stream = downloadStreamCompletedEventArgs.Result;
var image = new BitmapImage();
image.SetSource(stream);
StoredImage = image;
};

wc.OpenReadAsync(new Uri(request));

No comments:

Post a Comment

If you like this post, please leave a comment :)