title: Working With Web Response Stream and De-serialization into C# object
body: <p>I have 2 specific questions with regards to passing a <code>System.IO.Stream</code> (from a method) and deserialization into object (another method).</p>
  
  <p>XML Response I get from a <code>WebRequest</code> (please note there are no root tags)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;response id="-2d953936:14174bb0cf3:-5213"&gt;
        &lt;date&gt;2013-10-01 12:01:55.532999&lt;/date&gt;
        &lt;status&gt;
               &lt;current&gt;open&lt;/current&gt;
               &lt;next&gt;after&lt;/next&gt;
               &lt;change_at&gt;16:00:00&lt;/change_at&gt;
        &lt;/status&gt;
        &lt;message&gt;Market is open&lt;/message&gt;
        &lt;unixtime&gt;1380643315&lt;/unixtime&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p>Method 1 - ResponseMethod - Currently returning string</p>
  
  <pre><code>private static string GetResponse(HttpWebRequest request)
  {
        var v_Response = request.GetResponse();
        var v_DataStream = v_Response.GetResponseStream();
  
        var v_Reader = new System.IO.StreamReader(v_DataStream);
        var x_XMLResponse = v_Reader.ReadToEnd();
  
         //Close all Stream logic
         v_Reader.Close(); v_DataStream.Close(); v_Response.Close();
  
         return x_XMLResponse;
  }
  </code></pre>
  
  <p>Method 2 - Convert the XML to an object</p>
  
  <pre><code>// I would use XDocument and Lin2XML to get my typed object - for example MarketStatus
  </code></pre>
  
  <p>Questions are:</p>
  
  <ol>
  <li>I am currently passing string from Method 1. That doesnt help me in deserializing from XML to object. Should I be passing the return value as <code>StreamReader</code> and then use that as an input into method 2 to get my typed object. Is that a standard approach or there are better ways to this?</li>
  <li>My ultimate objective is that the return value from second method should be an object.</li>
  </ol>
  
  <p>Additional Note: </p>
  
  <ol>
  <li>The reason this functionality is broken into 2 methods because I want the web response method and deserailization separate for testing purposes.</li>
  <li>I don't have an XSD but have created a <code>MarketStatus</code> Class</li>
  </ol>
  
  <p>Any code snippets/suggestions will really appreciate</p>