开发者

Bug with reading data using WebClient

In our application we use Silverlight on the client-side. It downloads data from the server using WebClient:

WebClient wcGetDataFundSet = new WebClient();
wcGetDataFundSet.OpenReadCompleted += (s, e2) =>
{
    // Do something with the data.
};
wcGetDataFundSet.OpenReadAsync(new Uri(this.uriString));

When I open this.uriString in the browser, correct result is displayed. On another developer's machine everything works just fine. On mine delegate doesn't even fire. Tr开发者_如何学编程ied using "http://google.com/index.html" and some other URLs. It worked, but e2.Result threw an exception of type 'System.Reflection.TargetInvocationException'. Then I changed code to this and it worked:

WebClient wcGetDataFundSet = new WebClient();
wcGetDataFundSet.DownloadStringCompleted += (s, e2) =>
{
    // Do something with the data.
};
wcGetDataFundSet.DownloadStringAsync(new Uri(this.uriString));

Windows XP SP3, Visual Studio 2010 and IE 8 on every machine. Do you have any ideas where the problem was? Thanks in advance.


I know this thread is very old and the problem might be solved meanwhile, but i hate threads without an answer...

My Solution was

DownloadDataAsync

instead of openReadAsync. The corresponding events are

DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)

DownloadDataCompleted(object sender, DownloadDataCompleteEventArgs e)

I only got this Exception while trying to convert the result to string on error (forgot return after handling e.Error).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜