I have a Silverlight app that is getting a list of items from a service on my website. I am passing it as an ObservableCollection with the following function:
public ObservableCollection<Dictionary<string, object>> GetItems(string transetDocId)
{
ObservableCollection<Dictionary<string, object>> result = new ObservableCollection<Dictionary<string, object>>();
foreach (DataRow dr in ((DataTable)HttpContext.Current.Session["ItemDataTable"]).Rows)
{
Dictionary<string, object> tempD = new Dictionary<string, object>();
foreach (DataColumn dc in ((DataTable)HttpContext.Current.Session["ItemDataTable"]).Columns)
tempD.Add(dc.ColumnName, dr[dc.ColumnName]);
result.Add(tempD);
}
return result;
}
Everything was working fine. And now, with no changes that I can think of, it has started returning the following error.
The HTTP request to ‘http://www.example.com/Services/Example.svc’ has exceeded the allotted timeout. The time allotted to this operation may have been a portion of a longer timeout.
I’ve stepped through the code. I’m firing off the GetItemsAsync() method in the client. The service sees the call, creates the result and returns it. But the GetChecksCompleted() method never gets hit (Yes, I’m adding an event handler). After a few minutes, I get the error.
I tried modifying the code so that it returns one long comma/semicolon/pipe delimited string instead of an observable collection and everything runs fine.
Why won’t the ObservableCollection work?
More information:
The error I’m getting actually occurs in the generated file Reference.cs in the line right before the return statement:
public System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>> EndGetItems(System.IAsyncResult result) {
object[] _args = new object[0];
System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>> _result = ((System.Collections.ObjectModel.ObservableCollection<System.Collections.Generic.Dictionary<string, object>>)(base.EndInvoke("GetItems", _args, result)));
return _result;
}
The problem was actually with some of the data. There was a DBNull value in some of the columns which was causing trouble during the deserialization. The error message that it was throwing was just completely off.
I was able to figure out what was going on after enabling tracing as outlined here: http://msdn.microsoft.com/en-us/library/ms733025.aspx
Thanks to anatoliiG for getting me going in the right direction.