For class we have to follow a tutorial to create a silverlight website that searches DIGG for a given topic. (Using this tutorial as a base: http://weblogs.asp.net/scottgu/archive/2010/02/22/first-look-at-silverlight-2.aspx)
We have to use the following code to fetch the information from DIGG.
private void buttonSearch_Click(object sender, RoutedEventArgs e)
{
string topic = textboxSearchTopic.Text;
WebClient digg = new WebClient();
digg.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(digg_DownloadStringCompleted);
digg.DownloadStringAsync(
new Uri("http://services.digg.com/1.0/story.getAll?count=10&topic="+topic));
}
void digg_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
DisplayStories(e.Result);
}
}
private void DisplayStories(string xmlContent)
{
XDocument document = XDocument.Parse(xmlContent);
var stories = from story in document.Descendants("story")
where story.Element("thumbnail")!=null
select new DiggStory
{
Id = (string)story.Attribute("id"),
Title = (string)story.Element("title"),
Description = (string)story.Element("description"),
ThumbNail = (string)story.Element("thumbnail").Attribute("src"),
HrefLink = (string)story.Attribute("link"),
NumDiggs = (int)story.Attribute("diggs")
};
gridStories.ItemsSource = stories;
}
And when bushing the buttonSearch, We get the error:
An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at System.Net.OpenReadCompletedEventArgs.get_Result()
at DiggSample.Views.Search.Digg_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
at System.Net.WebClient.OpenReadOperationCompleted(Object arg)
I already know the Digg API is outdated, but I do not think this error has anything to do with it. (We even get a local XML file, which we can use but it still doesn't work)
I have no idea what is causing this and we aren't get much help from our teacher, so I hope somebody can help us.
Thanks, Thomas