對於課程,我們必須按照教程創建一個搜索DIGG以查找給定主題的silverlight網站。 (以本教程爲基礎:http://weblogs.asp.net/scottgu/archive/2010/02/22/first-look-at-silverlight-2.aspx)使用Digg API和URI處理程序的未知錯誤(silverlight)
我們必須使用以下代碼從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;
}
和襯套的buttonSearch的時候,我們得到的錯誤:
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)
我已經知道Digg的API已經過時,但我不認爲這個錯誤有什麼關係呢。 (我們甚至得到一個本地的XML文件,我們可以使用它,但它仍然不起作用)
我不知道是什麼原因造成這種情況,我們沒有從我們的老師那裏得到太多的幫助,所以我希望有人可以幫助我們。
感謝, 托馬斯
什麼是InnerException? –