开发者

WebClient DownloadStringAsync is loading very slowly

Update: I have tried HttpWebRequest and it is also exhibiting the same behaviour.

I'm trying to use WebClient DownloadStringAsync to retrieve some (very small) data in an Outlook add-in (VSTO/.Net 4.0). It's taking about 10-15 seconds before it even makes the request.

Having utilized the powers of google, I was pointed towards the fact that it was trying to pick up the proxy settings, and that I should set these to null. I tried that both in code:

WebClient serviceRequest = new WebClient();
serviceRequest.Proxy = null;

and by adding an App.config file and putting:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.net>
    <defaultProxy enabled="false">
      <proxy/>
      <bypasslist/>
      <module/>
    </defaultProxy>
  </system.net>
</configuration>

I added the file through the 'New Item' interface (I'm not sure if its being picked up and utilised).

Neither of these solutions has worked. Is there any things that I could try changing.

The code in question is as follows:

class MyClient
{
    string url = "http://192.168.1.99:4567/contact.json?token={0}&email={1}"; 

    WebClient serviceRequest = new WebClient();

    public void getContact(string email, DownloadStringCompletedEventHandler methodName)
    {
        Uri target = new Uri(String.Format(url, "1234", email));
        serviceRequest.Proxy = null;

        if(serviceRequest.IsBusy)
        {
            serviceRequest.CancelAsync(); // Changed our mind and switched email
        }
        serviceRequest.DownloadStringComp开发者_开发技巧leted += methodName;
        serviceRequest.DownloadStringAsync(target);
    }
}


Discovered what the problem was.

I was working on a Windows 2003 Server Virtual Machine (what I had available). As soon as I installed Windows 7 (and environment) on another VM and tried it the problem vanished.

The server machine does not have IE Enhanced Security turned on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜