silverlight – WebClient失败,远程服务器“NotFound”

我正在构建一个wp7应用程序.我正在使用WebClient从服务器获取数据.在过去,它一直在工作,虽然突然间它失败了.

static void downloadData(string uri,Action<object,DownloadStringCompletedEventArgs> onComplete)
    {
        Debug.WriteLine("Downloading: " + uri);
        WebClient data = new WebClient();
        data.DownloadStringCompleted += new DownloadStringCompletedEventHandler(onComplete);
        data.DownloadStringAsync(new Uri(uri));
    }

    static void data_SectionDownloadCompleted(object sender,DownloadStringCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            // throws NotFound
            throw e.Error;
        }

        // ...
    }

当我在浏览器中找到有问题的URI时,它运行正常.

例外:

"The remote server returned an error: NotFound." {System.Net.WebException}

我在这做错了什么?

更新:我重新启动了模拟器,现在它工作正常.奇怪的.也许这是模拟器中的一个问题?希望我无法在实际设备上重现它.

解决方法

NotFound是一个通用错误,基本上意味着’错误’.背后有一个真正的例外,你需要挖掘才能找到.我找到的最简单的方法是 Intellitrace,它允许您查看Web服务器上发生的每个异常.如果你在NotFound之前看,你会发现支持它的真正例外.

如果无法选择Intellitrace,请在服务器和客户端上添加更多/更好的日志记录.谷歌有许多提示,是深度调试的一个很好的例子:

http://www.mostlydevelopers.com/blog/post/2009/01/14/debugging-tips-ndash3b-the-remote-server-returned-an-error-notfound.aspx

相关文章

如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的...
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,...
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如...
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不...
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:...
我需要根据Silverlight中的某些配置值设置给定控件的Style.我...