tags:

views:

323

answers:

1

I'm using .NET 2.0 to make a simple webservice call. From most machines, I don't need to do anything special. However, one client is on a corporate network that uses a proxy autoconfig script. Just about everything I can find (e.g. http://msdn.microsoft.com/en-us/magazine/cc300743.aspx#S3) tells me that I shouldn't need to do anything. .NET will read the proxy settings from the registry and "just work". Yeah right.

If the client uses their browser to visit the webservice URL first, then my webservice call does work. However, after some period of time the webservice calls stop working with a 407 (Proxy Authentication Required) error.

I've tried explicitly setting the proxy (as suggested by http://stackoverflow.com/questions/284511/get-proxy-configuration-before-accessing-an-external-webservice-net-2-0), but haven't had any luck.

I found this MS knowledgebase article with information on calling WinHttpGetProxyForUrl in WinHTTP.DLL. If I pull the autoconfigurl setting out of the registry and use it in a call to WinHttpGetProxyForUrl, it seems to work, but it just seems wrong to have to go there. Does anyone know the "right way" to get .NET to use the default IE proxy autoconfig script? Thanks.

+1  A: 

Whether or not it's supposed to work, I'd not to depend on auto-config scripts for web services. Those are meant to configure proxy services for web browsers.

The IT organization should figure out which proxy is to be used on that particular machine, for that particular web service, and set it in the config file.

John Saunders
Thanks John. I'd love to avoid the auto-config scripts if .NET would do it's job and transparently use IE's proxy settings. And as much as I'd love to drop this on their IT department, I'd much rather get a workable (if imperfect) solution without them.
Don Pratt
If it were using IE settings, it would be using the same auto-config scripts IE is using. That's what should be avoided.
John Saunders
I guess I don't understand why auto-config scripts are OK for calling a server to retrieve a webpage but not for calling a server to run a web service.
Don Pratt
One is being called by a program with a GUI running on behalf of a human. The other is being called by another program. Consider this experiment: pretend that auto-config scripts do not exist at all. How would you write the code to configure the correct proxy server for your web service client?
John Saunders
Well, I'd probably end up with a "network settings" dialog similar to the one in IE and tell users to contact their IT folks for the correct settings :)
Don Pratt
It would be simpler, of course, if their IT folks distributed the proxy server address, perhaps using Group Policy. Surely the proxy server address for a particular machine doesn't change frequently. Not any more, I would think. I always thought auto-configure scripts were for roaming situations, where you had to figure out to use the work proxy or the home proxy or the hotel proxy.
John Saunders