Serialize XmlDocument & send via HTTPWebRequest

后端 未结 3 1941
半阙折子戏
半阙折子戏 2021-01-14 21:29

I\'m trying to figure out how to properly serialize my XmlDocument and send it via a HTTPWebRequest object.

Here\'s what I have thus far:

Stream reques         


        
3条回答
  •  借酒劲吻你
    2021-01-14 22:23

    I'm guessing this question is related to the previous one about 2 xml documents not being able to be combined into one document without wrapping them both in a root node first (C# XmlDocument Nodes).

    If that is the case then you don't want to be serialising the XmlDocuments and sending them to the WebService. Serializing the objects is for transporting/storing the actual object, not the data. You want to just send the webservice the data not the object so just concatenate the two xml documents and send that.

    use XmlDocument.OuterXml to get the XmlDocument as a string. ie:
    
    XmlDocument doc1 = new XmlDocument();
    doc.LoadXml("Some XML");
    XmlDocument doc2 = new XmlDocument();
    doc2.LoadXml("Some other XML");
    StringBuilder sb = new StringBuilder();
    sb.Append(doc1.OuterXml);
    sb.Append(doc2.OuterXml);
    

    The just send sb.ToString() to the WebService.

    Hope I haven't got completely the wrong end of the stick.

提交回复
热议问题