クラスでは、チュートリアルに従って、DIGG で特定のトピックを検索する Silverlight Web サイトを作成する必要があります。(このチュートリアルをベースとして使用: http://weblogs.asp.net/scottgu/archive/2010/02/22/first-look-at-silverlight-2.aspx )
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 ファイルも取得しますが、それでも機能しません)
何が原因なのかわからず、先生からもあまり助けてもらえないので、誰か助けてくれることを願っています.
ありがとう、トーマス