this is a small part of my code that allows me to request a file through a load balancer, reading this XML file gives me the server's name (only node inside the XML Document) if the machine isn't inside the LAN then it won't be able to query the website. I give it a longer timeout to make sure that I don't get a ton of errors emailed to me if the network is laggy.
Here is the XML file Structure.
<?xml version="1.0" encoding="utf-8"?>
<Server>
JSODYAPP01T
</Server>
Here is the Code that retrieves the information
WebRequest request = WebRequest.Create(xmlLocation);
request.Timeout = 90000;
using (WebResponse response = request.GetResponse())
using (XmlReader xmlReader = XmlReader.Create(response.GetResponseStream()))
{
while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Text)
{
serverName = xmlReader.Value.ToString();
serverName = serverName.Replace("\r", "");
serverName = serverName.Replace("\n", "");
serverName = serverName.Replace(" ", "");
}
}
}
is there a better way of doing this?