2

I have a Web API method that is secured by Windows Authentication. Here's the client code:

var uri = new Uri(@"https://myapi.mysite.com/api/method");
var request = HttpWebRequest.Create(uri);
request.Method = "GET";
request.ContentLength = 0;
request.ContentType = "application/json";
request.Timeout = 30 * 60 * 1000;

request.Credentials = new NetworkCredential("userName", "password", "domain");

using (var response = request.GetResponse())
{
    using (var responseStream = new StreamReader(response.GetResponseStream()))
    {
        Console.WriteLine(responseStream.ReadToEnd());
    }
}

When https://myapi.mysite.com/api/method takes less than about 5 minutes to return, all is well. As soon as it takes 5 minutes or longer (5 minutes seems to be a magic number), I start getting a 401 back. I'm using the same credentials both times. Everything is the same except the amount of data the server is processing (obviously more data leading to longer processing time).

The specific 401 I'm getting is the '401 - Unauthorized: Access is denied due to invalid credentials.' message.

I've experimented with KeepAlive, CredentialCache, setting a server timeout and many other options/approaches and can't get anything to work.

The server is IIS 7.5 running under a service account whose password never expires.

Any help would be appreciated.

Jason Anderson
  • 189
  • 1
  • 4
  • 18

0 Answers0