removing/extracting soap header and body from soap message

后端 未结 1 1017
醉梦人生
醉梦人生 2021-01-17 01:45

I have a soap message shown below. I would like to get only request element and its child nodes.




        
相关标签:
1条回答
  • 2021-01-17 02:08

    You have the wrong namespace in your second example, and you didn't follow the complete example from the linked answer.

    XNamespace.Get("soap="http://www.w3.org/2003/05/soap-envelope")
    

    The parameter passed in to XNamespace.Get should be the URI only:

    XNamespace.Get("http://www.w3.org/2003/05/soap-envelope")
    

    Then your second example will return something like:

    <soap:Body xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
      <Request ReqRespVersion="large" Version="1" EchoToken="1.0" xmlns="http://mynamespace.com">
      </Request>
    </soap:Body>
    

    If you want just the child(ren) elements of the Body, then you need to add FirstNode like this:

    SoapBody = myXDocument.Descendants(Xns + "Body").First().FirstNode.ToString()
    

    Which will give you this:

    <Request ReqRespVersion="large" Version="1" EchoToken="1.0" xmlns="http://mynamespace.com">
    </Request>
    
    0 讨论(0)
提交回复
热议问题