c# - HTTP 407 proxy authentication error when calling a web service -


I am working on a net application which calls 3rd party web services over the Internet. The service does not use SOAP, so we manually create an XML request document, send it through the HTTP service, and retrieve an XML response.

Our code is a Windows service that is run in context, is a normal Windows domain account, and behind a proxy server (Microsoft ISA Server) that requires NTLM authentication. The account running our service is allowed to access the internet through a proxy server.

The code looks like this:

  // Create the Request Item HttpWebRequest Request = (HttpWebRequest) WebRequest.Create (url); request. Method = "post"; // Configure proxy server to authenticate that requires Windows domain credentials. request. Proxy = new webpage (ProxyEdder) {usage default credentials = true}; // Set the other required headers request. Accept = acceptable template type; Request.Headers.Add (HttpRequestHeader.AcceptCharset, Acceptable Charset); Request.Headers.Add (HttpRequestHeader.Accept encoding, "none"); Request.Headers.Add (HttpRequestHeader.AcceptLanguage, "en-gb"); Request.Headers.Add (HttpRequestHeader.CacheControl, "No-Store"); Request.Headers.Add (HttpRequestHeader.ContentEncoding, "None"); Request.Headers.Add (HttpRequestHeader.ContentLanguage, "en-gb"); Request.ContentType = Request MimeType; Request.ContentLength = requestBytes.Length; // method call (stream stream = requestBytes, 0, requestBytes.Length) by using stream stream = request.GETRequestStream ()); } HttpWebResponse response = (HttpWebResponse) request.GetResponse (); // Remove data from feedback without depending on HTTP content-length header // (We can not trust all providers to set it correctly) Const int buffer size = 1024 * 64; & Lt; Byte & gt; Feedback = new list & lt; Byte & gt; (); (Stream stream = new bufffream stream (feedbackGetterSponsScream (), buffer size)) {int value; While ((value = stream.ReadByte ())! = -1) {responseBytes.Add (byte) value); }}  

This works fine when the proxy server is off or the URL has been whitelisted according to the authentication requirement, but as soon as the authentication is active, it is always the HTTP 407 Fails with error

I have put the above code in a test harness, and tried every method I could think of without having to successfully configure the request.Proxy property.

Then I saw that all third party web services have to call us HTTPS when I tried to use them as an HTTP, then the proxy authentication started working. Is there an extra hoop? Do I have to jump through HTTPS to get proxy authentication and play well?

PS: The same problem is with Open Source Chickenwall Proxy Server, so I can not write it now as a bug in ISA server.

PPS: I know that you can configure proxy settings in app.config , but (A) code should not do any such difference by doing so, and ( B) Application design requires that we read the proxy settings from the database on runtime.

Have you tried setting a proxy in app.config?

To disable the proxy, add the following configuration to the App.config file

  & lt; System.net & gt; & Lt; DefaultProxy enabled = "wrong" usage default credentials = "false" & gt; & Lt; Proxy / & gt; & Lt; Bypasslist / & gt; & Lt; Module / & gt; & Lt; / DefaultProxy & gt; & Lt; /system.net>  

To enable the proxy and use the default proxy settings (specified in IE), add this configuration to your App.config

  & Lt; System.net & gt; & Lt; DefaultProxy enabled = "true" usage default credentials = "true" & gt; & Lt; Proxy / & gt; & Lt; Bypasslist / & gt; & Lt; Module / & gt; & Lt; / DefaultProxy & gt; & Lt; /system.net>  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -