473,377 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 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 1806

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

Similar topics

3
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....
2
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...
2
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...
9
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....
14
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...
3
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...
2
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...
0
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...
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.