I was spending some time composing Soap Messages using System.Xml, but I found a strange behavior of System.Xml while adding nodes to an existing XmlDocument.
I have an empty soap envelope like this:
What I want is to add the method payload from the next information:
My first attempt was a mix between AppendChild and InnerXml
However the result output was
Note the empty namespace declaration in the name element, and the bad news is that ASP.Net needs the namespace information to deserialize the request message, so I have to hack System.Xml to avoid this behavior.
I take a look to news://microsoft.public.dotnet.xml and I only a found a few messages talking about how to remove the attribute once the final message is composed, but I would like to avoid the empty namespace (xmlns=””) while composing the doc. After playing a little bit with the API I found the solution:
Instead of creating the method element with AppendChild, I’m going to manually build the whole method element in a string, and assign it to the body InnerXml property:
Now it works…