Silverlight Web服务的SecurityException

时间:2010-09-05 23:04:16

标签: c# silverlight

我一直在关注这个Silverlight tutorial,使用Twitter代替Digg。一切正常,直到我尝试从服务中获取数据的步骤。

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项目,它工作正常。我能做错什么?

1 个答案:

答案 0 :(得分:0)

您可能遇到跨站点脚本(XSS)错误。看看这里:Making a Service Available Across Domain Boundaries