Hey - this is great, thanks. I'm trying to make a simplied method - one that just downloads an xml file (doesn't even do the extra work of calling a web service). I was able to modify your code to work in IE, but it just returns null in fireFox. The goal is to have a single, sync, static method that just gets the xml file for you. For example, you request a local xml file on your own web server, specify the appropriate URL, and it returns the file content. Do you know what I'm doing wrong such that this doesn't work with FireFox?
public static string DownloadXmlStringSync(string url)
{
ScriptObject _XMLHttpRequest;
StringBuilder _Body;
XmlWriter _Writer;
StringBuilder _Result = new StringBuilder();
try
{
_XMLHttpRequest = HtmlPage.Window.CreateInstance("XMLHttpRequest");
_Body = new StringBuilder();
_Writer = XmlWriter.Create(_Result);
_XMLHttpRequest.Invoke("open", "GET", url, false);
_XMLHttpRequest.Invoke("setRequestHeader", "Content-Type", "text/xml; charset=utf-8");
_Writer = XmlWriter.Create(_Result);
_Writer.WriteStartDocument();
_Writer.WriteStartElement("soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
_Writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
_Writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");
_Writer.WriteStartElement("Body", "http://schemas.xmlsoap.org/soap/envelope/");
_Writer.WriteEndDocument();
_Writer.Flush();
_XMLHttpRequest.Invoke("send", _Result.ToString());
ScriptObject dom = (ScriptObject)_XMLHttpRequest.GetProperty("responseXML");
string strXml = (string)dom.GetProperty("xml");
return strXml;
}
catch (Exception ex)
{
throw;
}
}
Tim Stall
http://timstall.dotnetdevelopersjournal.com