Contact   •   Products   •   Search

Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs

Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?


I’m in the final stages of getting my West Wind Web Store app ported over to 2.0 by getting rid of all of the obsolete function calls and other non fatal messages. Frankly most of these deprecated APIs changes are lame and for the most part simple name changes or attaching the same logic to some other object. While I think cleaning up interfaces is not a bad idea, deprecating many of these old apis in this ways is a pain. I know, I know I can turn this off, but this code ships to customers and they'd have to turn it off too...

 

Anyway, I bit the bullet and went through and cleaned most of this up. The vast majority of these where related to ADO.NET parameters and ASP.NET Page Script objects, which have all moved to a separate Scripting object. Most of the stuff is just using a different method or possibly a different subobject - pure manual labor.

 

The last one I’m left with though is one I don’t know how to replace.

 

Warning         1        'System.Net.WebProxy.GetDefaultProxy()' is obsolete: 'This method has been deprecated. Please use the proxy selected for you by default. http://go.microsoft.com/fwlink/?linkid=14202'          D:\projects2005\wwIPStuff\wwHTTP.cs     500     31      wwIPStuff

 

I use GetDefaultProxy in my wwHttp component to automatically use Internet Explorer settings by default. One of the reasons I need to do this is so I can debug my HTTP requests with Fiddler which works through the IE settings.

 

I think from the reading that I’ve done on this, that .NET 2.0 now uses this setting by default now, so it’s probably no longer necessary to use this method, but I wonder then how you’d turn this behavior off.

 

Anybody know what the recommended replacement procedure is?

 

 

HTTP Retrieval Problems in ASP.NET 2.0 applications 

As a side note I’ve noticed that there is a problem with Whidbey and Proxy behavior. Under ASP.NET 2.0 doing XmlDocument.Load() or opening an Http Connection with HttpWebRequest, the connection seems to hang for about 10 seconds before starting to retrieve data on the first data retrieval.

 

This only happens under ASP.NET operation (or some other non-UI desktop account) – in a Console test of the same identical code runs fine without hesitation.

 

You can find out more about this here – I posted this as a bug on the feedback center:

 

http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=50fb0803-eea8-48cb-8d60-ac9db4433994

 

 

MSDN Feedback Center

Incidentally I have to say that MSDN Feedback center is a royal pain in the ass to use. It’s next to impossible to determine when an how a bug was updated and whether I need to respond to a bug or not. I see changes but often it’s just a status change without any action required. At one time I had 10 open issues and trying to keep up with it, I ended up missing a few valuable messages and feedback.

 

The process of submitting also is too tedious. I really gotta wonder WTF there isn’t a Web Service built straight into Visual Studio to do this. This would save a significant amount of re-typing all the information that the system can pick up automatically for me like the version number, language etc. When I fill out a bug I want to just fill out the error info and not take 5 minutes just to get to the point of actually filling a bug report.

 

Make Donation


Feedback for this Post

 
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Blair Jennings July 12, 2005 @ 8:43am
The latest MSDN mag (August 2005) has a great article on just this subject. Just use this call:

IWebProxy aProxy = WebRequest.DefaultProxy;

and you are done.

Blair
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Rick Strahl July 17, 2005 @ 3:20pm
Thanks Blair. Excellent article!

http://msdn.microsoft.com/msdnmag/issues/05/08/AutomaticProxyDetection/default.aspx

The solution to the problem is to explicitly disable default proxy support in web.config, which essentially forces a direct connection:
<system.net>
<defaultProxy>
<proxy usesystemdefault="False"/>
</defaultProxy>
</system.net>

Voila HTTP access is fast again.
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by shriop July 18, 2005 @ 8:18am
Nice to know. I've got several spiders that I'll need to update code on it looks like.
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Rick Strahl July 25, 2005 @ 5:50pm
FWIW, the property Blair was talking about is the static:

WebRequest.Proxy = HttpWebRequest.DefaultWebProxy;

This still begs the question on how to turn off proxy detection since auto-proxy now appears to be the default. Assigning null to the proxy? Declaratively I suspect we can use the same defaultproxy settings in the .config file to turn this off.
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Breezback November 29, 2005 @ 9:23am
Hi,

I think I have same problem,
I copied my ws to another machine in my intranet, with the release of .net 2.0.

now when after deploying my client (winform which connects to ws), I get the following error:

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

Now , I wanted to know why my dev computers are fine , when others are throwing this exception? should I modify the machine.config or the app.config , is it client-or-server side problem??

Please give me the new config explicitly!

Thanks in advance,

Ilan :)
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Amit February 02, 2006 @ 1:12am
I have the same issue as that of Breezback, i tried using proxy approach but no help.
The environment i put my code does not have any proxy settings in the IE, and i dint get any proxy error while adding a webreferance there
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Handy June 01, 2006 @ 11:38pm
Hi,

I have the same problem with Breezback.
I tried to call a webservice from a desktop application and it returned that error.

Anybody knows how to solve this problem?

Thanks in advance..
# aspnet Deploying ASP.NET 2.0
by eggheadcafe.com articles October 02, 2006 @ 1:30am
# DotNetSlackers: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0
by DotNetSlackers Latest ASP.NET News October 12, 2006 @ 4:42pm
# Deploying ASP.NET 2.0 - microsoft.public.dotnet.framework.aspnet | Google Groups
by microsoft.public.dotnet.framework.aspnet Google Group February 19, 2007 @ 7:28pm
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Rick April 23, 2007 @ 8:31pm
solution with
IWebProxy aProxy = WebRequest.DefaultProxy;


is pretty good and it solved the block.

my question is how about on WINCE, as WebRequest.DefaultProxy is not supported by .net compact framework...

thanks

rick
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Rick Strahl June 10, 2007 @ 12:58pm
Rick - I think you can probably set the proxy to null and that should work.
# Google Groups: microsoft.public.dotnet.framework.aspnet
by microsoft.public.dotnet.framework.aspnet Google Group June 19, 2007 @ 8:45am
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Michael July 25, 2007 @ 4:21pm
Rick - the system.net configuration options enable you the configure the default proxy as you need. Eg, mine is:

<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true" >
<proxy autoDetect="True" scriptLocation="http://wpad.premiers.qld.gov.au/wpad.dat"/>
</defaultProxy>
</system.net>

The above does exactly what IE does.

Im sure you can configure the default to what ever you require.
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Nick H. W. December 06, 2007 @ 9:16am
Hi pepole:

I have been through ways of failure for this, finally got right one.

1. refresh web service, enter the link like : http://testgsrs/Safety_Incident.asmx

2. In Reference.cs, change following clause to the new one:

this.Url = global::FA.Properties.Settings.Default.FA_testgsrs_Safety_Incident;

it fixed.

I have tried following ways in the assumption that proxy setting is the main reason. but not.



Nick. H. W.

//web.config

<!--
<system.net>
<defaultProxy>
<proxy usesystemdefault="False"/>
</defaultProxy>
</system.net>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true" >
<proxy autoDetect="True" scriptLocation="http://ccm.ga.local/proxy.pac"/>
</defaultProxy>
</system.net>
-->

// in .cs

//System.Net.WebRequest.DefaultWebProxy = System.Net.HttpWebRequest.DefaultWebProxy; //Proxy,
//System.Net.IWebProxy aProxy = System.Net.WebRequest.DefaultWebProxy; // FASafetyConnection, DefaultProxy
//System.Net.WebRequest.DefaultWebProxy = null;
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Paul December 16, 2008 @ 1:59am
Hi Guys.

I don't understand the posts above. What should I do to this line of code:

this.WebRequest.Proxy = WebProxy.GetDefaultProxy();

Visual Studio doesn't like:

this.WebRequest.Proxy = WebRequest.DefaultProxy;

Please explain in simple terms.

Cheers
Paul
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Nutshell July 20, 2009 @ 4:24pm
If you are using VS - then intellesense should have showed you the proper method

this.WebRequest.Proxy = WebRequest.DefaultWebProxy;
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Avi August 04, 2009 @ 1:35pm
Use the following
WebRequest.Proxy = HttpWebRequest.DefaultWebProxy
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by Praveen August 23, 2010 @ 6:48am
Thanks, Michael.
Your solution worked.
# re: Replacing deprecated System.Net.WebProxy.GetDefaultProxy() in .NET 2.0?
by SRN September 19, 2011 @ 5:00pm
Michael's comments helped. Setting the complete proxy settings in web.config did the trick.
http://www.west-wind.com/weblog/posts/2005/Jul/11/Replacing-deprecated-SystemNetWebProxyGetDefaultProxy-in-NET-20#122350
 


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2014