2011-01-08 129 views
1

更新:我試過HttpWebRequest並且它也表現出相同的行爲。WebClient DownloadStringAsync加載非常緩慢

我試圖使用WebClient DownloadStringAsync檢索Outlook加載項(VSTO/.Net 4.0)中的一些(非常小的)數據。它甚至在發出請求之前需要大約10-15秒。

利用谷歌的權力,我指出了它試圖拿起代理設置的事實,我應該將它們設置爲空。我想,無論是在代碼:

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

,並通過添加一個App.config文件,並把:

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

我通過「新建項目」界面添加的文件(我不知道它被拾起和利用)。

這些解決方案都沒有工作。有什麼我可以嘗試改變的。

有問題的代碼如下:

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.DownloadStringCompleted += methodName; 
     serviceRequest.DownloadStringAsync(target); 
    } 
} 

回答

0

發現了什麼問題。

我正在使用Windows 2003 Server虛擬機(我有可用的)。一旦我在另一臺虛擬機上安裝了Windows 7(和環境)並嘗試使用,問題就消失了。

服務器計算機沒有啓用IE增強安全性。