Skip to content

Instantly share code, notes, and snippets.

@DanielOberg
Created November 23, 2010 15:37
Show Gist options
  • Save DanielOberg/711946 to your computer and use it in GitHub Desktop.
Save DanielOberg/711946 to your computer and use it in GitHub Desktop.
Gives a queryable XDocument without namespace problems
/*
XDocument result = HttpSOAPRequest(string_to_send, to_this_url);
var resultatLinq = from c in result.Descendants("something")
select c.Element("something_else");
*/
XDocument HttpSOAPRequest(String xmlfiletosend, string url) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlfiletosend);
HttpWebRequest req = ( HttpWebRequest ) WebRequest.Create(url);
req.ContentType = "application/soap+xml; charset=utf-8";
req.Accept = "text/xml";
req.Method = "POST";
Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);
XDocument doc_result = XDocument.Parse(r.ReadToEnd().Replace("xmlns", "xmlns2").Replace(":", ""));
return doc_result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment