1

of the following code i want to get the bold elements: _connectionId and return.

There are two return tags, I need to get "return" and the relative value and the same for "_connectionid"

<Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <Body>
       <login_newResponse xmlns=\"http:XXXXXXXXXXXX.wsdl"> 
          <return>
              <_**connectionid**>@@@@@@@@@@@@@AHT@Q@@@@@D@GR@SUEF</_**connectionid**>
              <**return**>CONNESSIONE AVVENUTA</**return**> 
          </return> 
       </login_newResponse> 
    </Body> 
 </Envelope>

I've tried with this code

XDocument XML = XDocument.Load(s);
var lv1s = from lv1 in XML.Descendants("Body")
           select lv1.Nodes();

I get a list of XML strings but it's impossible to get a specific element. Is there a way to extract whatever element just indicating the name?

Thanks!

Matteo Defanti
  • 212
  • 1
  • 5
  • 17
  • This looks like a SOAP response, why aren't you just it deserializing it into an object? – JNYRanger Jul 07 '15 at 20:14
  • I've searched and I didn't found anything about consuming SOAP Services for WebApi, so I am wrapping all by myself. – Matteo Defanti Jul 07 '15 at 20:22
  • Anyway if you have any suggestion Soap relative I'm Interested too – Matteo Defanti Jul 07 '15 at 20:23
  • WebAPI only supports RESTful services. You shouldn't be using it if you want to use SOAP. Use WCF instead. Also are you writing your own SOAP service? If so you should really think about using REST instead as SOAP is a dying protocol. – JNYRanger Jul 07 '15 at 20:25
  • That is not my own Soap Service. My application is for the front end html + angularJs and on the backend I have my own RestAPIs. To interface to the external App I'am exposing on the Web there is an old Soap Service that I'm wrapping. There are not many function and i have to use just a few... that's why I decided to wrap the soap – Matteo Defanti Jul 07 '15 at 20:30
  • Ah i get it! You really just need a SOAP client, no need to use WebAPI or fancy libraries. This is all built into .NET framework. Take a look at this answer: http://stackoverflow.com/a/1302559/2359643 on how to consume a SOAP service. Visual Studio does all the magic for you when you provide a WSDL to generate a client. – JNYRanger Jul 07 '15 at 20:41
  • Thanks for your help. I have already tried that way but the tool did not generate me the Client object. It only gets me the objects such ar login_newRequest, login_newRequestBody, login_newreturn (which has the 2 fields _connectionID and return), login_newResponse and login_newResponseBody – Matteo Defanti Jul 07 '15 at 20:53

1 Answers1

0

If you just want to quickly find those two values, you can do:

        XNamespace ns = "http:XXXXXXXXXXXX.wsdl";
        var data = XML.Root.Elements("Body").Elements(ns + "login_newResponse").Elements(ns + "return")
            .Select(e => new { ConnectionId = (string)e.Element(ns + "_connectionid"), Return = (string)e.Element(ns + "return") })
            .FirstOrDefault();

Likely you'll need to replace "http:XXXXXXXXXXXX.wsdl" with the "real" namespace.

dbc
  • 104,963
  • 20
  • 228
  • 340