title: Remove Xml declaration from web service response
body: <p>I have the following web service. The output has the XML declaration <code>&lt;?xml version="1.0" encoding="utf-8"?&gt;</code> at the top of the file. I need to get rid of it for my mobile app to work correctly. How do I do it?</p>
  
  <pre><code>[WebMethod]
      public XmlDocument GetTileData(string user)
      {
          var xml = new XmlDocument();
          xml.LoadXml(string.Format(@"&lt;tile&gt;
                                    &lt;visual&gt;
                                      &lt;binding template='TileWideSmallImageAndText02'&gt;
                                        &lt;image id='1' src='http://server/images/{0}_wide.png'/&gt;
                                        &lt;text id='1'&gt;Custom Field : {1}/text&gt;
                                        &lt;text id='2'&gt;Custom Field : {2}&lt;/text&gt;
                                        &lt;text id='3'&gt;Custom Field : {3}&lt;/text&gt;
                                      &lt;/binding&gt;
                                      &lt;binding template='TileSquarePeekImageAndText01'&gt;
                                        &lt;image id='1' src='http://server/images/{0}_square.png'/&gt;
                                        &lt;text id='1'&gt;Custom Field&lt;/text&gt;
                                        &lt;text id='2'&gt;{1}&lt;/text&gt;
                                      &lt;/binding&gt;    
                                    &lt;/visual&gt;
                                  &lt;/tile&gt;", value1, value2, value3, value4));
  
          return xml;
      }
  </code></pre>
  
  <p>Edit 1: I tried to return the Xml Element instead of the document, but it's not working either. I still see the declaration.</p>
  
  <pre><code> [WebMethod]
          public XElement GetTileData(string user)
          {
              var xml = XDocument.Parse(string.Format(@"&lt;tile&gt;
                                        &lt;visual&gt;
                                          &lt;binding template='TileWideSmallImageAndText02'&gt;
                                            &lt;image id='1' src='http://server/images/{0}_wide.png'/&gt;
                                            &lt;text id='1'&gt;Custom Field : {1}/text&gt;
                                            &lt;text id='2'&gt;Custom Field : {2}&lt;/text&gt;
                                            &lt;text id='3'&gt;Custom Field : {3}&lt;/text&gt;
                                          &lt;/binding&gt;
                                          &lt;binding template='TileSquarePeekImageAndText01'&gt;
                                            &lt;image id='1' src='http://server/images/{0}_square.png'/&gt;
                                            &lt;text id='1'&gt;Custom Field&lt;/text&gt;
                                            &lt;text id='2'&gt;{1}&lt;/text&gt;
                                          &lt;/binding&gt;    
                                        &lt;/visual&gt;
                                      &lt;/tile&gt;", value1, value2, value3, value4));
  
              return xml.Root;
          }
  </code></pre>
  
  <p>Edit 2: I was able to get around this issue by using a HttpHandler. See my answer below.</p>