<< .NET C# and Com Interoperability
|
Home
|
ASP.NET 2.0 - Web Deployment Projects >>
posted @ Saturday, September 17, 2005 9:07 PM
Had an issue getting a Windows service running in a client's environment. The service makes a web request to get some data from a web page, and the request wasn't getting around their proxy server. The admin had disabled the proxy but since the service runs under the system account, it wasn't picking up his changes. I did some googling and sent him some code for the app.config System.Net settings:
<defaultproxy>
<proxy usesystemdefault="false" bypassonlocal="true"/>
<bypasslist>
<add address="externalurl\.com" />
</bypasslist>
</defaultproxy>
It seemed so simple, but it didn't get the job done. Further googling found some shoddy code for bypassing a proxy that was very confusing. One place suggessted setting HttpWebRequest.Proxy = null, which threw a runtime error. Another suggested creating a WebProxy object with your proxy server's settings and setting HttpWebRequest.Proxy to that. That seemed odd to me since I was trying to AVOID the proxy server.
Actually what helped us out was the exception that was thrown when we set the proxy to null. It said something like: "Cannot set Proxy to null, try setting it to GlobalSelectProxy.GetEmptyWebProxy(). Funny thing about that was there is no GlobalSelectProxy object. So I did some more searching and found it was a mistake in the exception text. Finally I ended up with the following:
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(path);
req.Proxy = GlobalProxySelection.GetEmptyWebProxy();
That did the trick!
Now, if only I could get this BindIFilterFromStream thing working.