title: C# code using XmlDictionaryReader
body: <p>I am receiving an xml document into a WCF service and want to verify a specific element/attribute in the document.  I can verify that the contents are being read in with:-</p>
  
  <pre><code>using (XmlDictionaryReader reader = message.GetReaderAtBodyContents())
  {
      string content = reader.ReadOuterXml();
  }
  </code></pre>
  
  <p>However, I now want to get the value of a particular attribute and element in the XML. I have tried <code>reader.GetAttribute("name", "namespace")</code> and <code>reader.ReadToFollowing</code> followed by <code>reader.ReadElementContentAsString</code>, but the values are always <code>null</code>. What am I doing wrong?</p>
  
  <hr>
  
  <p>I've tried various combinations of </p>
  
  <pre><code>string test1 = reader.GetAttribute("retry_number", "ns1 location");
  string test2 = reader.GetAttribute("ns1:retry_number", "ns1 location");
  </code></pre>
  
  <p>The XML defines the element in a different namespace as <code>&lt;ns1:retry_number&gt;1&lt;/ns1:retry_number&gt;</code> where <code>ns1</code> has already been declared.  </p>
  
  <p>Other code tried is:</p>
  
  <pre><code>reader.ReadToFollowing("ns1:retry_number"); 
  string test3 = reader.ReadElementContentAsString()
  reader.ReadToFollowing("ns1:retry_number");
  reader.MoveToFirstAttribute();
  string test4 = reader.Value;
  </code></pre>
  
  <p>Firstly I would like some success reading the element and then move on to the attribute. The test variables are always set to <code>null</code>, despite in the first step I can see the XML in the content variable when I read the outer XML.</p>