title: RESTful service not returning XML as expected
body: <p>I have a WCF RESTful service that is supposed to return a name and surname of a customer as a XML response, the service is defined as indicated below</p>
  
  <pre><code>[OperationContract]
      [WebInvoke(Method = "POST",
          RequestFormat = WebMessageFormat.Xml,
          ResponseFormat = WebMessageFormat.Xml,
          BodyStyle = WebMessageBodyStyle.Bare,
          UriTemplate = "/GetNameAndSurname")]
      string GetNameAndSurname();
  </code></pre>
  
  <p>The problem I'm experiencing is that the XML response that is returned was not in normal XML as expected, for example</p>
  
  <pre><code>&lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;
   &amp;lt;Customer;&amp;#xD;
    &amp;lt;Name&amp;gt;Andre&amp;lt;/Name&amp;gt;&amp;#xD;
    &amp;lt;SurnameName&amp;gt;Lombaard&amp;lt;/SurnameName&amp;gt;&amp;#xD;
   &amp;gt;
  &lt;/string&gt;
  </code></pre>
  
  <p>I'm not sure if it is the service returning the response this way or if it is the way I'm reading the data, just for informational purposes I included the code I use to read the response below,</p>
  
  <pre><code>var request = HttpWebRequest.Create(url);
  request.Method = "POST";
  request.Timeout = 2 * 60 * 1000;
  byte[] byteArray = Encoding.UTF8.GetBytes(xml);
  request.ContentType = "text/xml";
  request.ContentLength = byteArray.Length;
  var dataStream = request.GetRequestStream();
  dataStream.Write(byteArray, 0, byteArray.Length);
  dataStream.Close();
  var response = request.GetResponse();
  dataStream = response.GetResponseStream();
  StreamReader reader = new StreamReader(dataStream, Encoding.UTF8);
  dataStream.Flush();
  var results = reader.ReadToEnd();
  reader.Close();
  dataStream.Close();
  response.Close();
  </code></pre>
  
  <p>How do I get normal XML without having to perform various replacements on the characters received in the response.</p>
  
  <p>At the moment I replace the characters with the code below. This is not ideal</p>
  
  <pre><code>results = results.Replace("&lt;/string&gt;", String.Empty);
  results = results.Replace("&amp;lt;", "&lt;");
  results = results.Replace("&amp;gt;&amp;#xD;", "&gt;");
  results = results.Replace("&amp;gt;", "&gt;");
  results = Regex.Replace(results, "&lt;string .*?\\&gt;", String.Empty);                
  </code></pre>