2011-10-17 106 views
2

客戶端網站上有一個代理服務器,所有外部請求都必須經過。我正在調用需要代理設置的外部Web服務。在開發環境中設置虛擬代理服務器

我用來設置網絡請求代理的代碼可以在下面看到。

我會如何在我的開發人員環境中設置測試代理服務器來驗證我的代碼是否正常工作?

  string url = String.Format("http://currencyconverter.kowabunga.net/converter.asmx/GetConversionAmount?CurrencyFrom={0}&CurrencyTo={1}&RateDate={2}&Amount={3}", CurrencyFrom.Text, CurrencyTo.Text, formattedDate, amount); 

      WebRequest request = WebRequest.Create(url); 

      if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["proxyLogin"])) 
      { 
       WebProxy proxy = new WebProxy(); 

       string proxyUrl = ConfigurationManager.AppSettings["proxyUrl"]; 

       if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["proxyPort"])) 
       { 
        proxyUrl += ":" +ConfigurationManager.AppSettings["proxyPort"]; 
       } 

       // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set. 
       proxy.Address = new Uri(proxyUrl); 
       // Create a NetworkCredential object and associate it with the 
       // Proxy property of request object. 
       proxy.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["proxyLogin"], ConfigurationManager.AppSettings["proxyPassword"]); 
       request.Proxy = proxy; 
      } 

      WebResponse response = request.GetResponse(); 

回答

2

你可以在你的開發環境中安裝代理服務器,並以這樣的方式,該服務被部署到防火牆之外配置的機器,你需要只通過代理服務器連接到服務。

+0

謝謝你有更多的信息嗎?我可以在Windows 2008開發環境中使用哪些代理軟件? – Burt

+0

看到這個:http://www.youngzsoft.net/ccproxy/windows-server-proxy-server.htm和http://en.softonic.com/s/windows-proxy-server-2008更多。 – Neeta