XNamespace ws = "http://myweb.com/webservices";
string sessionId = (string)Response.Descendants(ws + "sessionId").FirstOrDefault();
Query Xdocument
-
29-06-2023 - |
Question
I have a soap message from an web service as an Xdocument and wish to extract the session id element for future use. I am able to loop over the the response using the code below, but how would I query the soap to return the sessionid
Dim dnas = From node In Responce.DescendantNodes _
Select node
For Each node In dnas
If TypeOf node Is XElement Then
Debug.Print(DirectCast(node, XElement).Name.ToString)
Else
Debug.Print(node.ToString)
End If
Next
The soap:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateResponse xmlns="http://myweb.com/webservices">
<CreateResult>
<ResultCode>0</ResultCode>
<ResultDescription>Authentication Successful</ResultDescription>
<sessionid>04e1b723-ff93-4af0-94f4-2245ccf11f42</sessionid>
</CreateResult>
</CreateResponse>
</soap:Body>
</soap:Envelope>
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow