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