We are using web service with basic authentication. It all worked all fine, till owners of web service implemented balancing service. Which is simply redirects requests to different instances of web service.
The problem is that after being redirected basic authentication fails. There is "request authentication credentials was not passed" exception.
Additional info:
We have to create request manually.
var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(Settings.Default.HpsmServiceAddress)); req.Headers.Add("Authorization", "Basic aaaaaaaaaaa"); req.PreAuthenticate = true; req.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested; req.UserAgent = "Apache-HttpClient/4.1.1 (java 1.5)"; req.KeepAlive = false; ServicePointManager.Expect100Continue = false; req.ContentType = "text/xml; charset=utf-8"; req.Method = "POST"; req.Accept = "gzip,deflate"; req.Headers.Add("SOAPAction", actionName); byte[] buffer = Encoding.UTF8.GetBytes(envelop); Stream stm = req.GetRequestStream(); stm.Write(buffer, 0, buffer.Length); stm.Close(); WebResponse response = req.GetResponse(); string strResponse = new StreamReader(response.GetResponseStream()).ReadToEnd(); response.Dispose();
We are redirected with HTTP 307 redirect