Loading Image from WCF Service Dynamically Metro Apps

I found it really hard to solve this problem in Windows 8 when you want to Load Images Dynamically from Server Side using WCF to your Metro App since most of code snippets avaiable online will not work with Metro Apps


Basically here is the solution answer for you use the following snippets will solve your problem


Load Images from Web Service

  1. HelperService.HelperManagerClient client = new HelperService.HelperManagerClient();
  2.             byte[] imageData = await client.GetCountryFlagAsync(countryCode);
  4.             var ims = new InMemoryRandomAccessStream();
  5.             var dataWriter = new DataWriter(ims);
  6.             dataWriter.WriteBytes(imageData);
  7.             await dataWriter.StoreAsync();
  8.             ims.Seek(0);
  10.             BitmapImage bitmap = new BitmapImage();
  11.             bitmap.SetSource(ims);
  12.             imgFlag.Source = bitmap;