My ASP.NET application calls web services( including Google Web API) and it is a requirement to access it through Proxy Server that requires Authentication. It works correctly with Microsoft ISA server (see my post Set defaultProxy configuration Element for Proxy Server) .
But it didn't work with Squid proxy server Authentication.
When I specified useDefaultCredentials=true, the WebException returned : “HTTP status 417: Unknown“.
After some investigation I found that 417 is actually Expectation failed and then that MS Web Services have HttpWebRequest and the Expect: 100-continue Header Problem .
So I had to override GetWebRequest for Web Services to set Expect100Continue = false and requests are going through Squid proxy server.Hurray!
using System.Net;
namespace Google_Web_APIs_Demo.Google
{
public partial class GoogleSearchService//: System.Web.Services.Protocols.SoapHttpClientProtocol
{
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest wr= base.GetWebRequest(uri);
HttpWebRequest wrHttp = wr as HttpWebRequest;
if (wrHttp != null)
wrHttp.ServicePoint.Expect100Continue = false;//avoid expects error http://haacked.com/archive/2004/05/15/449.aspx
return wr;
}
}
}
UPDATE: The behavior could be changed in config file:
<configuration>
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
</configuration>
UPDATE: Slightly related problem:
If you have error: "The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF", add
add in the web.config the following (in brown) (from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=21106&SiteID=1&PageID=0 )
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
</configuration>
Update: the solution described above helped for one client with Squid, but din't help on another site.