Call Web Services through SQuid proxy server with authentication requested

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.

posted @ Wednesday, September 13, 2006 11:06 AM

Print

Comments on this entry:

# UseDefaultCredentials Problem with Web Service

Left by Jean at 11/9/2006 9:48 PM
Gravatar
Hi there, I'm hoping you could maybe help me.

I've had a similar problem to you except when I use the code: UseDefaultCredentials = true; then I get an error: HTTP Status 401: Unauthorized. I searched like crazy for a solution to this and everywhere I look people say that UseDefaultCredentials is the Solution...but for me its the problem.

I know my problem has to do with credentials. The web service simply isn't receiving my credentials. My web service is accessed perfectly when I hardcode my credentials with this code:
MyWebService.Credentials = new System.Net.NetworkCredential("<MyUserName>", "<MyPassword>");

...but I of course don't want to hard code it. Why does UseDefaultCredentials not work for me? Is there some IIS setting or Web.Config details I need to change?

Any help will greatly be appreciated. Thank you.

# re: Call Web Services through SQuid proxy server with authentication requested

Left by Michael Freidgeim at 11/10/2006 8:43 AM
Gravatar
Jean,
In my post http://geekswithblogs.net/mnf/archive/2006/03/08/71663.aspx I've describe how to "Change Identity of user account in Application Pool" to the account that is authorized on your network resource.
Hope this helps.

Michael.

# re: Call Web Services through SQuid proxy server with authentication requested

Left by Steve at 12/12/2006 7:41 PM
Gravatar
I was also wondering if you could help me with a similar issue.

I have a .Net 2.0 application that connects with a company server across the Internet. I use Squid with NTLM authentication on my end, but the application uses different credentials. Thus, when I try to connect I get a 407 error. (By the way, I only have access to my client app and Squid.)

Is there a way to prefer the username and password entered into the .Net application to the NTLM authenication?

Thanking you in advance, Steve.

# re: Call Web Services through SQuid proxy server with authentication requested

Left by Michael Freidgeim at 12/13/2006 7:35 AM
Gravatar
Steve,
In my post //geekswithblogs.net/mnf/archive/2006/03/08/71663.aspx I've described how to change user account for ASP.Net application. Another way is to use impersonation. You can do it in web.config or "Activate Windows Impersonation Selectively" http://www.ftponline.com/vsm/2004_05/magazine/columns/qa/default_pf.aspx

Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 6 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910