使用Digg的API和URI处理程序未知错误(Silverlight的) [英] Unknown error using Digg API and URI handler (silverlight)

查看:157
本文介绍了使用Digg的API和URI处理程序未知错误(Silverlight的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关类,我们必须遵循一个教程创建Silverlight的网站,搜索DIGG对于一个给定的主题。 (使用本教程为基础:的http://weblogs.asp.net/scottgu/archive/2010/02/22/first-look-at-silverlight-2.aspx)

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)

我们必须使用以下code来从DIGG的信息。

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;
        }

和衬套buttonSearch的时候,我们得到的错误:

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)

我已经知道Digg的API已经过时,但我不认为这个错误有什么关系呢。 (我们甚至得到了本地XML文件,我们可以用它,但它仍然无法正常工作)

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

推荐答案

有关code的这一部分:

For this section of code:

if (e.Error != null)
{
    DisplayStories(e.Result);             
}

您是说,显示的故事,如果e.Error是的的空。我想你想切换的条件说了 e.Error == NULL ,因为这将意味着没有错误及其安全使用的结果。你可能想要把一个断点条件检查 e.Error 的值,看看是否有异常存在。

You're saying to display the stories if e.Error is not null. I think you want to switch the condition to say e.Error == null, as that would mean there was no error and its safe to use the result. You may want to put a breakpoint at the condition to inspect the value of e.Error to see if you have an exception there.

编辑:

当你改变了条件 e.Error == NULL 和什么都没有发生,那是因为错误是不为null,所以你的 DisplayStories (e.Result)语句根本不会被解雇了。

When you changed the condition to e.Error == null and nothing happened, that's because the error was non-null, so your DisplayStories(e.Result) statement never fired.

问题外, SecurityException异常,是因为Silverlight的浏览器内的应用程序不允许你做与外部网站的呼叫,除非该网站有一个Silverlight跨域策略文件。不幸的是,Digg的政策文件中不再允许跨域访问的,这意味着你将不能,除非你有充分的信任外的浏览器上运行你的应用程序,使这个电话。请参阅在Silverlight 网络安全访问限制了解更多详情。

The exception in question, the SecurityException, happens because Silverlight in-browser applications do not allow you to make calls to external websites unless that website has a Silverlight cross-domain policy file. Unfortunately, Digg's policy file no longer allows cross-domain access, which means that you won't be able to make this call unless you run your app with full trust out-of-browser. See Network Security Access Restriction in Silverlight for more details.

要运行你的应用程序作为外的浏览器应用程序以完全信任,在Visual Studio中,右键单击您的项目,然后选择属性。在Silverlight的选项卡,选中该复选框,说:能用完的浏览器。然后单击说按钮出的浏览器设置。在对话框中,检查说盒子需要提升的信任的浏览器外运行的时候。在调试选项卡上,开始行动,选择输出浏览器应用程序,然后从下拉列表中的项目。

To run your app as an out-of-browser app with full trust, in visual studio, right-click your project and choose properties. On the "Silverlight" tab, check that box that says "enable running out of browser." Then click the button that says "Out of browser settings." In the dialog, check the box that says "require elevated trust when running outside the browser." In the "Debug" tab, for "Start Action," choose "Out of browser application" and select your project from the dropdown.

当你运行这种方式,你应该不会再得到SecurityException异常。

When you run this way, you should no longer get the SecurityException.

这篇关于使用Digg的API和URI处理程序未知错误(Silverlight的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆