Explicitely specify Default user credentials for Proxy Server.

Some time ago I wrote post "Call Web Services through SQuid proxy server with authentication requested"  and hoped, that I will not have more problems with Squid web proxy server.
However the solution wasn't sufficient for other site. I've tried a lot of things, started thread "Unable to access external web sites through Squid proxy server with required authentication." and posted suggestion to Microsoft "Add ability to specify credentials to defaultProxy configuration element".

But the best solution, that I found for the moment is  to create common function to set web proxy credentials and call it  for each Web Services call,HttpWebRequest call and replace  dataset.ReadXml(url)  with HttpWebRequest.GetRequest.
The function created expects up to 4 properties in appSettings section of Web.config
        <!--Web Proxy Credentials to use if useDefaultCredentials="true" doesn't help

    TODO move to separate ConfigurationSection, different from AppSettings

    <add key="ProxyUserName" value=""/>

    <add key="ProxyUserPassword" value=""/>

    <add key="ProxyAuthenticationType" value="Basic"/>

    <add key="ProxyUserDomain" value=""/>

    -->
and to be called like the following for web services


        AWSECommerceService aws = new AWSECommerceService();

         SetDefaultWebProxyCredentialsIfRequired(aws);

 

or for dataset.ReadXml

 

        IWebProxy proxyObject = CreateDefaultWebProxyWithCredentialsIfRequired(url);//WSClientHelper.

        if (proxyObject == null)

            ds.ReadXml(url);

        else

        {

            Stream strm = GetResponseStream(url, proxyObject);//HttpWebRequestHelper.

            ds.ReadXml(strm);

        }

The code of the SetDefaultWebProxyCredentialsIfRequired and other helper methods can be found here.

 

posted @ Friday, March 09, 2007 12:18 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 5 and 3 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910