WebException in GetResponse
Please excuse and redirect me if I'm posting in the wrong area but I'm hoping someone here at F5 can be some help.
I have a web application which uses a class library I created which, among other things, reads an XML file on the web host (an IIS 6 server/cluster). When I run the app locally in VS2010 or on my testing platform, also an IIS 6 server, it works fine. When I publish to my BIG-IP load-balanced 2 server Veritas Cluster, the code executes fine as long as I use each nodes' name but if I use the cluster's friendly name I get the following exception:
The underlying connection was closed: An unexpected error occurred on a receive.
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at Symantec.DataFactories.AdomdClientDataFactory.GetStoredProcedure()
There is more to the stack but that's the gyst of it. I had previously gone at the file more directly with HttpWebRequest.GetResponse() and switched to using XmlDocument.Load() in the hopes that I'd been doing something wrong. No joy.
The server is running DotNET 3.5 so the abundance of articles directing me to a fix for 1.0 aren't useful. I did attempt to fix it by setting the HttpWebRequest's KeepAlive to false. Again, no joy. I'm guessing that either we have something mis-configured on the servers or I need to modify my code to better deal with the load balancing. Here's the code I'm trying to run:
// Request and read the file.
try
{
// Read and cache the file
XmlDocument xmlFile = new XmlDocument();
xmlFile.Load(AbsoluteUrlUsingAuthority);
string fileContents = xmlFile.InnerXml;
HttpContext.Current.Cache.Insert(cacheKey, fileContents, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, CacheSlidingExpirationMinutes, 0));
}
catch
{
// Fall back to using WebResponse methodology for debugging
try
{
// Ask the web server for the file
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AbsoluteUrlUsingAuthority);
request.KeepAlive = false;
using (WebResponse response = request.GetResponse())
using (TextReader reader = new StreamReader(
response.GetResponseStream(), Encoding.GetEncoding("utf-8")))
{
// Read the contents of the file.
string file = reader.ReadToEnd();
// Close the stream.
reader.Close();
// Add the file to the cache, sliding expiration.
HttpContext.Current.Cache.Insert(cacheKey, file, null, Cache.NoAbsoluteExpiration,
new TimeSpan(0, CacheSlidingExpirationMinutes, 0));
}
}
catch (WebException webException)
{
if (webException.Status == WebExceptionStatus.NameResolutionFailure)
throw new Exception("Bad domain name", webException);
if (webException.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse response = (HttpWebResponse)webException.Response;
if (response.StatusCode == HttpStatusCode.NotFound)
{
throw new Exception(
string.Format("Requested file, {0}.xml, not found.
{1}", _command.CommandText, response),
webException);
}
if (response.StatusCode == HttpStatusCode.Forbidden)
{
throw new Exception(
string.Format("403 (Access denied) error accessing {0}.
{1}", AbsoluteUrlUsingAuthority, response),
webException);
}
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
throw new Exception(
string.Format("401 (Authentication required) error accessing {0}.
{1}", AbsoluteUrlUsingAuthority, response),
webException);
}
}
throw;
}
}
I've been pulling my hair out on this for weeks now so any guidance on debugging and/or troubleshooting from a coder's perspective, considering I have to work through a (human) proxy to take any actions on the server would be appreciated.