Created
November 23, 2010 15:37
-
-
Save DanielOberg/711946 to your computer and use it in GitHub Desktop.
Gives a queryable XDocument without namespace problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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