Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:04:52+00:00 2026-05-29T10:04:52+00:00

I have an SOAP response that looks similar to this: <?xml version=1.0 encoding=UTF-8?> <soapenv:Envelope

  • 0

I have an SOAP response that looks similar to this:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <getLoginResponse xmlns="http://<remotesite>/webservices">
        <person_id>123456</person_id>
        <person_name>John Doe</person_name>
    </getLoginResponse>
  </soapenv:Body>
</soapenv:Envelope>

I’ve been able to successfully extract the <get LoginResponse ...> node with the following LINQ code:

string soapResult = rd.ReadToEnd();

XNamespace ns = "http://<remotesite>/webservices";

XDocument xDoc = XDocument.Parse(soapResult);

var respUser = (from r in xDoc.Descendants(ns + "getLoginResponse")
                select new User
                           {
                               Name = r.Element("person_name").Value
                           }).FirstOrDefault();

However, the call to Name = r.Element("person_name").Value gives me an Object reference not set to an instance of an object error.

I looked into this further, and I see that if I run this query, all of the values (person_id, person_name) are in fact in the nested .Descendants().Descendants() XElement collection:

var respUser = (from r in xDoc.Descendants(ns + "getLoginResponse") 
                select r).Descendants().ToList();

So, what this tells me is in my original LINQ query, I am not extracting the nodes under <getLoginResponse> correctly.

How can I combine this together, using ... select new User { ... } to fill my custom object?

Doing something like:

var respUser = (from r in xDoc.Descendants(ns + "getLoginResponse").Descendants()
                select new User()
                              {
                                 Name = r.Element("person_name").Value
                              }).FirstOrDefault();

Doesn’t work very well 🙂

Thanks all for the solution – I omitted the namespace from the child elements, which caused my issue!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:04:53+00:00Added an answer on May 29, 2026 at 10:04 am

    You need to add a valid namespace to your query, in your example that would be "http://foobar/webservices", e.g.:

    XElement xml = XElement.Load(@"testData.xml");
    XNamespace foobar = "http://foobar/webservices";
    string personId = xml.Descendants(foobar + "person_id").First().Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WebService that returns XML in a SOAP response: <?xml version=1.0 encoding=utf-8
I have a small SOAP CGI gatewqay C++ program that reads an HTTP SOAP
I have a SOAP web service written in java communicating via XML-utf-8. My produced
I have a SOAP response that I'm processing in Java. It has a element
I have a SoapExtension that is intended to log all SOAP requests and responses.
We have SOAP web services in production that are relying on SOAP Headers (containing
I have a SOAP client in Ruby that I'm trying to get working with
I have a SOAP request that is known to work using a tool like,
I have a SOAP result set that the nuSoap extension has turned into a
I have an android application, that will call a SOAP web service for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.