Video on How to solve cross domain problem in Silverlight?


If you find my posts useful you may like to follow me on twitter or may like Facebook page of my blog If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

Debugging WCF Service from Silverlight: The Breakpoint will not currently be hit at WCF Service error


  1. Binding configuration at WCF has debugging enabled
  2. Cross domain problem has been take care of since WCF and Service is running on different servers.
  3. Visual studio is running in administrator credentials or credentials having enough permission to debug on server.

While working today I came across a requirement to debug WCF Service from Silverlight and it took me one hour to find the solution, I had above three assumptions met and I was not able to debug WCF Service from Silverlight.

I had architecture of solution as below,


There is nothing unusual in above architecture. I had Silverlight, Web Application and WCF as part of the same solution. Problems came when I tried to debug WCF service from Silverlight. I was getting below information at breakpoint in the service side and I was never able to hit the service while debugging.


I binged lot but did not get quiet good solution suggesting solving this. Eventually I found it very simple way to solve this.

Follow steps as below to hit the breakpoint in the service ,

Set web application as Startup project


Put breakpoint on Xaml.cs and run Silverlight application and once hitting breakpoint on XAML page stop for a while


While breakpoint on XAML is in hit select Tool from the menu and choose Attach to Process option


And then attach WCF host server.


Once after attaching WCF host server you should able to hit the breakpoint in WCF Service from Silverlight.

I hope this post was useful. Thanks for reading.

If you find my posts useful you may like to follow me on twitter or may like Facebook page of my blog If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.


Fetching selected value from List Box in Silverlight

Let us say you have a list box as below. You have a requirement that on click of button fetch value of the same row button belongs to.

For example if you are clicking second cross, you should able to fetch value Pinal, SqlServer , 500 from the list box.


In above list box

  • There is a button (cross image) in each item.
  • Text blocks bind with data.
  • List box is bind to the collection.

XAML of list box is as below,

<ListBox x:Name="lstData" Margin="5,7,6,15">
<DataTemplate >
<Grid x:Name="TopGrid">
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
<Button Margin="5,5,5,5" Click="Button_Click">
<Button.Template >
<ControlTemplate >
<Image Source="delete.png" VerticalAlignment="Center"   Height="30" Width="30"/>
<Grid x:Name="nestedGrid" Grid.Column="1">
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextTitle2Style}" />
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Text="{Binding Interest}"  Style="{StaticResource PhoneTextSubtleStyle}" />
<TextBlock Text="{Binding Totalposts}" Style="{StaticResource PhoneTextAccentStyle}"/>


Item source of list box is set to List of Bloggers.


Bloggers class is as below,

Note: Make sure you are calling OnNotifyPropertyChanged() after seeting the value of the property [Edited]

public class Bloggers : INotifyPropertyChanged
private string name;
public string Name
return name;
name = value;

private string interest;
public string Interest
return interest;
interest = value;

private int  id;
public int  Id
return id;
id = value;

private int  totalposts;
public int Totalposts
return totalposts;
totalposts = value;

#region INotifyPropertyChanged Members

public event PropertyChangedEventHandler PropertyChanged;

// Used to notify the page that a data context property changed
private void NotifyPropertyChanged(string propertyName)
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));





Now on click event of button if you want to fetch particular list item then first take data context as blogger


Then fetch list box item as below,


Now you would able to use data as below


On click event of button you need to write code as below to fetch particular item list value.

private void Button_Click(object sender, RoutedEventArgs e)

Bloggers data = (sender as Button).DataContext as Bloggers;
ListBoxItem bloggerToDeleteFromListBox = this.lstData.ItemContainerGenerator.ContainerFromItem(data)
as ListBoxItem;
var Name = data.Name

In this way you can fetch the value of particular list item. I hope this post was useful. Thanks for reading J

If you find my posts useful you may like to follow me on twitter or may like Facebook page of my blog If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

Creating Deep Zoom Images through c# code

In this quick post, I will show you the creation of deep zoom images from Image in Azure BLOB. You may come with a requirement where you need to create deep zoom images using code. If you need deep zoom images for Pivot Viewer you can very much create it using several tools available. However you may have to create deep zoom images using code in some scenario. I am going to share code snippet for the same.

Very first you need to include DeepZoomTools dll as a reference in your project.

Add namespace


Next you need to create Container and set the basic properties as below,


Next create list of images you want to convert as deep zoom image. For purpose of this post, I am taking only one image. That image is in Azure Blob. So for that I am giving URL of the Image saved in azure Blob. You can choose image from local storage as well.


In last step you need to create deep zoom images using the create method of CollectorCreator


For reference full source code is as below,

protected void Button1_Click(object sender, EventArgs e)

string directoryToSaveDeepZoomImages = "D:\\abc";

CollectionCreator collectionCreator = new CollectionCreator();
collectionCreator.TileSize = 256;
collectionCreator.TileFormat = Microsoft.DeepZoomTools.ImageFormat.Png;
collectionCreator.ImageQuality = 1.0;
collectionCreator.TileOverlap = 0;

List<Microsoft.DeepZoomTools.Image> images =
new List<Microsoft.DeepZoomTools.Image>();
images.Add(new Microsoft.DeepZoomTools.Image("azuerbloburlforimage"));

collectionCreator.Create(images, directoryToSaveDeepZoomImages);


In this way you can create deep zoom images. I hope this post was useful. Thanks for reading  Smile


If you find my posts useful you may like to follow me on twitter or may like Facebook page of my blog If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.

Upload Image from Silverlight to Azure BLOB using WCF

Working with Azure Blob is very common task you must be doing. Sometime you may come with requirement to upload an image from Silverlight client to Azure BLOB. In this post I am trying to help you in achieving this.

In this post I will show you below three stuffs.

  1. Uploading Image to Azure BOLB
  2. Abstracting BLOB upload code in WCF service
  3. Using WCF Service in Silverlight client to upload the image.

Expected Output


Flow of application

Step 1: On click event of Button File Dialog will open

Step 2: User will select Image and on selection Image will get uploaded in Azure Blob.

Step 3: On successful uploading URI of image will be returned from the service. Source property of Image control would be set to the returned URL.

Creating Service

Service Contract will have an function expose as operation contract as below,

public interface IBLOBImageUpload


string UploadImage(byte[] Image);


Service is implemented as below,

  • We are creating a new GUID to set as file name of the image
  • Converting input byte array to stream
  • Calling a function to upload stream to blob
  • And returning URL of uploaded image
public string  UploadImage(byte[] Image)
string rowKeynFileName = Guid.NewGuid().ToString();
System.IO.Stream stream = new System.IO.MemoryStream(Image);
string imageUri= UploadImageinBlob(stream, rowKeynFileName );
return imageUri;


Function to upload Image in BLOB is as below

  • It is taking stream as input to upload
  • It is taking filename to be given to upload image
  •  DataConnectionString is connection string to Azure storage.
  •  urlContainer is name of the public container
  • Creating blob name by appending .jpg extension
  • Returning URL of uploaded image.

public string UploadImageinBlob(Stream Streams,string FileName)
CloudStorageAccount account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("urContainer");
string uniqueBlobName = string.Format("{0}.jpg", FileName);
CloudBlob blob = container.GetBlobReference(uniqueBlobName);
blob.Properties.ContentType = "image\\jpeg";
Streams.Seek(0, SeekOrigin.Begin);
string url = blob.Uri.OriginalString;
return url;


Configuring Service EndPoint

There are many points you need to put in mind while configuring the service end point.

  • Change maxReceivedMessageSize to 2147483647
  • Change maxBufferSize to 2147483647
  • Change maxArrayLength to 2147483647
  • Change maxBytePerRead to 2147483647
  • Change maxDepth to 2147483647
  • Change maxTableCharCount to 2147483647
  • Change maxStringContentLength to 2147483647
  • In Service behavior change data contract serliazer max object graph value to 2147483647




<binding name="ServicesBinding"








maxStringContentLength="2147483647" />




<service name="Service.BLOBImageUpload" behaviorConfiguration="ServiceData.Service1Behavior">

<endpoint address="" binding="basicHttpBinding" contract=" Service.IBLOBImageUpload " bindingConfiguration ="ServicesBinding" />

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>





<behavior name ="ServiceData.Service1Behavior">

<serviceMetadata httpGetEnabled="true"/>

<serviceDebug includeExceptionDetailInFaults="false"/>

<dataContractSerializer maxItemsInObjectGraph ="2147483647"/>




<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />



Now your service is written. You can choose service to host anywhere you want.

Creating UI

I have kept UI as sweet and simple as possible. There is just a button and image control. On click of button FileDialogBOX will open and user can select an image to upload. After successful uploading, URL of uploaded image in Azure blob will be returned and that will be set as source of Image control

<Grid x:Name="LayoutRoot" Background="White">

<RowDefinition Height="100" />
<RowDefinition Height="*" />


<Button x:Name="btn" Height="100" Width="100" Click="btn_Click" Content="Upload Image" />
<Image Grid.Row="1" x:Name="img" Height="auto" Width="auto" />


Calling Service

You need to make a normal service call

  • On click event of the button opening the file dialog
  • Converting stream to byte array
  • Passing byte array as input to the function.
  • GetImageSource function is converting given string URL as image source to be set as source of image control

public partial class MainPage : UserControl

public OpenFileDialog fileDialog = null;
public MainPage()

private void btn_Click(object sender, RoutedEventArgs e)
Stream strm;
byte[] buffer = null; ;
fileDialog = new OpenFileDialog();
fileDialog.Multiselect = false;
fileDialog.Filter = "All Files|*.*";
bool? retval = fileDialog.ShowDialog();
if (retval != null && retval == true)
strm = fileDialog.File.OpenRead();
buffer = new byte[strm.Length];
strm.Read(buffer, 0, (int)strm.Length);

BLOBImageUploadClient proxy = new BLOBImageUploadClient ();

proxy.UploadImageAsync += new EventHandler<UploadImageCompletedEventArgs>(proxy_UploadImageCompleted);

void proxy_UploadImageCompleted (object sender, UploadImageCompletedEventArgs e)

img.Source = GetImageSource(e.Result.ToString());

private ImageSource GetImageSource(string fileName)
return new BitmapImage(new Uri(fileName, UriKind.Absolute));



This is what all you need to do as far as coding is concern. Yes you may need to put clientacccesspolicy.xml at the root location of server where you are hosting WCF service to avoid cross domain problem.

I hope this post was useful. Thanks for reading Smile

If you find my blogs useful you may like to,

Follow me on twitter

Like Facebook page of this blog

If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.