webclient返回未知错误

时间:2012-02-14 10:19:07

标签: c# windows-phone-7 webclient system.reactive caliburn.micro

我有一个简单的场景,我的应用程序为xml文件发出异步Web请求(mock for webservice)。

一切似乎都不错,但webclient总是返回UnknownError。

我在这里缺少什么?

以下是网络请求代码:

public void LoadNews()
{
    // to prevent caching append random string to uri
    Random rnd = new Random();
    Uri uri = new Uri(FeedUri +"?rnd="+rnd.Next());

    WebClient wc = new System.Net.WebClient();


    var o = Observable.FromEvent<DownloadStringCompletedEventArgs>(wc, "DownloadStringCompleted")
        .ObserveOn(Scheduler.ThreadPool)
        .Select(s => s.EventArgs.Result)
        .ObserveOn(Scheduler.Dispatcher)
        .Subscribe(r =>
            {
            // use caliburn.micro eventaggregator to publish message
            EventAggregatorHelper.EventAggregator.Publish(new NewsPostMessage(LoadNewsPosts(r)));
            }, () => { });

    wc.DownloadStringAsync(uri);
}

这是辅助类:

public class EventAggregatorHelper
{
    static EventAggregator _eventAggregator = new EventAggregator();
    public static EventAggregator EventAggregator
    {
        get { return _eventAggregator; }
    }
}

0 个答案:

没有答案