471,086 Members | 909 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

C# VS.Net 1.1 (2003) - trouble with using IE proxy server settings

1
C# VS.Net 1.1 (2003) - trouble with using IE proxy server settings

I've got a program that detects if it can connect to a webservice. It sends a System.Net.WebRequest and then checks the information it gets back to findout if it can connect to the service properly. If there is an error it will catch an exception and everything is fine. This used to work wonderfully, until somebody decided they needed to use a proxy server. (rats!) It's written in C# and uses .Net 1.1. I know that .Net 2.0 fixes a bunch of stuff with this issue, but right now I don't have an option to move to 2.0 on this project. Here is the code:

Expand|Select|Wrap|Line Numbers
  1. if ((connected && null != ConfigurationSettings.AppSettings["PortalServer"])||(ConfigurationSettings.AppSettings["PortalServer"].StartsWith("http://localhost")))
  2.             {
  3.                 try
  4.                 {
  5.                     // In case a proxy server is being used via the Internet Explorer Settings
  6.                     System.Net.WebProxy proxy = System.Net.WebProxy.GetDefaultProxy();        // Get default proxy settings
  7.  
  8.                     if(proxy.Address != null)                                                // If there is an address then use it
  9.                     {
  10.                         Uri proxyURI = new Uri(proxy.Address.ToString());
  11.                         System.Net.GlobalProxySelection.Select = new System.Net.WebProxy(proxyURI);
  12.  
  13.                         WebProxy proxyObject =    new WebProxy(proxyURI,true);
  14.                         proxyObject.Credentials = System.Net.GlobalProxySelection.Select.Credentials.GetCredential(proxyURI,"Basic");
  15.                         proxyObject.BypassProxyOnLocal = false;
  16.  
  17.                         // Create a new 'HttpWebRequest' Object to the mentioned URL.
  18.                         HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
  19.                             ConfigurationSettings.AppSettings["PortalServer"] + "?wsdl");
  20.  
  21.                         request.Method = "GET";
  22.                         request.ContentType = "application/x-www-form-urlencoded";
  23.                         request.KeepAlive = true;
  24.                         request.Timeout = 10000;
  25.                         request.ProtocolVersion = HttpVersion.Version10;
  26.                         request.Proxy = proxyObject;
  27.                         Console.WriteLine("\nThe 'Proxy Server' of the protocol used is {0}",request.Proxy.ToString());
  28.  
  29.                         System.Net.WebResponse response = request.GetResponse();
  30.                         string responseText = (new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd());
  31.                         response.Close();
  32.                         connected = responseText.IndexOf("name='DataPortal'") > -1;
  33.                         lastRequestSuccessful = true;
  34.                     }
  35.                     else
  36.                     {
  37.                         System.Net.WebRequest request = System.Net.WebRequest.Create(
  38.                             ConfigurationSettings.AppSettings["PortalServer"] + "?wsdl");
  39.                         System.Net.WebResponse response = request.GetResponse();
  40.                         string responseText = (new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd());
  41.                         response.Close();
  42.                         connected = responseText.IndexOf("name='DataPortal'") > -1;
  43.                         lastRequestSuccessful = true;
  44.                     }
  45.                 }
  46.                 catch(Exception ex)
  47.                 {
  48.                     if (lastRequestSuccessful)
  49.                         log.Error("Could not connect to the data portal", ex);
  50.                     lastRequestSuccessful = false;
  51.                     connected = false;
  52.                 }

In the App.Config file I've entered the following:
Expand|Select|Wrap|Line Numbers
  1. <system.net>
  2.         <defaultProxy>
  3.             <proxy proxyaddress = "http://proxyserveraddress:80" bypassonlocal = "false"/>
  4.         </defaultProxy>
  5.    </system.net>

Right now I'm getting the following error:
System.Net.WebException: The operation has timed-out.
at System.Net.HttpWebRequest.GetResponse()
at CnpXpress.WindowsForms.Common.Offline.DataPortalDe tectionStrategy.IsConnected() in c:\projects\mohave\trunk\src\windowsforms.common\o ffline\dataportaldetectionstrategy.cs:line 81

Anybody have any ideas?

Thanks in advance.
Jun 19 '07 #1
0 1654

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jeffrey Tate via DotNetMonster.com | last post: by
14 posts views Thread by el_sid | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.