title: Parsing XML from a stream, C# / SoapUI
body: <p>I'm trying to get the value of "payload" from the following piece of XML that's sent with SoapUI:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="localhost"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;loc:HTTPWebService&gt;
           &lt;!--Optional:--&gt;
           &lt;loc:input&gt;Test&lt;/loc:input&gt;
           &lt;payload&gt;Data&lt;/payload&gt;
        &lt;/loc:HTTPWebService&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>Here's the C# bit:</p>
  
  <pre><code>string xmlPayload = "";
  
  XmlDocument xmlSoapRequest = new XmlDocument();
  
  using (Stream receiveStream = HttpContext.Current.Request.InputStream)
  {
      receiveStream.Position = 0;
  
      using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
      { 
          xmlSoapRequest.Load(readStream);
          xmlPayload = xmlSoapRequest.SelectSingleNode("/payload/@value").Value;
      }
  }
  return xmlPayload;
  </code></pre>
  
  <p>The problem is that currently "xmlPayload" ends up with the value of null and the request fails. The XML is properly loaded but for some reason "XmlPayload" is empty and SoapUi responds with "System.NullReferenceException: Object reference not set to an instance of an object." How can I get parse the "Data" value from "payload" properly?</p>