我正在构建一个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,请在服务器和客户端上添加更多/更好的日志记录.谷歌有许多提示,是深度调试的一个很好的例子: