Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically using a WebProxy with WPAD script

I am trying to call a webservice. I need to use a proxy that uses a WPAD script. The URL to this WPAD script is different for different deployments of the application.

Although IE has the correct proxysettings, the application is running as a windows service running under Local System account, so the application does not know the IE-settings for this windows-user.

Putting the following in app.config works:

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true" >
        <proxy autoDetect="True" scriptLocation="http://url.to/wpad.dat"/>
    </defaultProxy>
</system.net>

But this has the restriction that it cannot be configured by the user. Is there a way to do the above dynamically from (C#-)code? I also suspect the above will change behaviour of webservices that should not go through a proxy (but I have not verified that).

At http://msdn.microsoft.com/en-us/library/system.net.webproxy.aspx I found the helpful text: "(For an example that demonstrates using the WPAD feature, see the documentation for the IWebProxyScript class.)" but I have not found the example :(.

like image 334
Jan-Jaap van der Geer Avatar asked Jan 17 '12 13:01

Jan-Jaap van der Geer


1 Answers

This article on code project shows how to use windows APIs to execute the PAC script and return the correct proxy details for a given url: http://www.codeproject.com/Articles/12168/Using-PAC-files-proxy

You could use the function to find out the proxy details, and then configure the web service objects proxy directly, or change WebRequest.DefaultProxy.

like image 99
sga101 Avatar answered Oct 11 '22 01:10

sga101