My soap service receives a XML and i need to add soap enevelope to the xml before i send it to a HTTP service, i get a error at
line httpDocumet.DocumentElement.AppendChild(xml.DocumentElement);
how can i append soap headers to my xml?
[WebMethod]
public XmlDocument HelloWorld(XmlDocument xml)
{
XmlDocument httpDocumet = new XmlDocument();
XmlElement soapEnvelope = httpDocumet.CreateElement("soap", "Header", "http://schemas.xmlsoap.org/soap/envelope/");
soapEnvelope.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
soapEnvelope.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
httpDocumet.AppendChild(soapEnvelope);
XmlElement soapBody =httpDocumet.CreateElement("soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
httpDocumet.DocumentElement.AppendChild(soapBody);
httpDocumet.DocumentElement.AppendChild(xml.DocumentElement);
ERRROR MSG
System.Web.Services.Protocols.SoapException:
Server was unable to process request.
—> System.ArgumentException: The node to be inserted is from a
different document context. at
System.Xml.XmlNode.AppendChild(XmlNode
newChild) at
WebService1.Service1.HelloWorld(XmlDocument
xml)
You need to first
ImportNodeand thenAppendChild.See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.importnode.aspx