0
我一直在關注這個Silverlight tutorial,使用Twitter而不是Digg。一切工作正常,直到我嘗試從服務中獲取數據。SecurityException和Silverlight Web服務
private const string TWITTER_API_URL_FORMAT = "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name={0}";
private void Button_Click(object sender, RoutedEventArgs e)
{
string username = searchBox.Text;
string url = String.Format(TWITTER_API_URL_FORMAT, username);
WebClient twitterService = new WebClient();
twitterService.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitterService_DownloadStringCompleted);
label.Text = "Loading... " + url;
twitterService.DownloadStringAsync(new Uri(url));
}
void twitterService_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
label.Text = String.Format("Error: {0}", e.Error);
return;
}
// ...
}
它失敗,出現以下錯誤:
[System.Security.SecurityException] = {System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<E...
我不知道爲什麼會這樣。該URL是合法的。我有一個wp7 Silverlight項目,使用這個相同的代碼,它工作正常。我可能做錯了什麼?