472,952 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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
  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);
  13.                         WebProxy proxyObject =    new WebProxy(proxyURI,true);
  14.                         proxyObject.Credentials = System.Net.GlobalProxySelection.Select.Credentials.GetCredential(proxyURI,"Basic");
  15.                         proxyObject.BypassProxyOnLocal = false;
  17.                         // Create a new 'HttpWebRequest' Object to the mentioned URL.
  18.                         HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(
  19.                             ConfigurationSettings.AppSettings["PortalServer"] + "?wsdl");
  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());
  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 1775

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

Similar topics

by: Robb Gilmore | last post by:
Hello, We have a C#.NET app which runs as a windows service. Periodically it needs to post information via the internet to a remote server. For the posting, we are using HttpWebRequest class....
by: Iceman | last post by:
I gave a VB.NET client which comsumes a webservices. The VB.Net client is behind a proxy server. The problem is when the VB.NET client i behind a proxy is goes very slow. It does get response from...
by: Jeffrey Tate via DotNetMonster.com | last post by:
The error is: The proxy settings on this computer are not configured correctly for Web discovery. MSDN states that this is caused by: This error appears in the Add Web Reference dialog box if...
by: Codex Twin | last post by:
I am re-sending this in the hope that it might illicit a response. I have a corporate client who forces their workstations to get the proxy server details using an automatic proxy discovery script....
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
by: armando perez | last post by:
Hi, this is my first time here, but I was looking for something that may help me, and still, I haven't found something to use. I'm using a website made in .NET with C#, when I'm running my site...
by: rcp | last post by:
Hi all, I've read all posts from all existing threads and none of them worked to solve my problem, although its exactly the same. I'll try to explain my case and see if a kind soul could help me...
by: Godzilla | last post by:
Hi all, My problem is when I open a ASP.NET Project in VS.NET 2003, it shows up "A connection with server could not be established". Both new projects and existing project are not working! I...
by: gjones | last post by:
Hi, I am new to web services but I have been asked to connect to an external web service through Visual Studio 2003. The problem that I have is that the company who developed the web service...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.