I have the following web service. The output has the XML declaration <?xml version="1.0" encoding="utf-8"?>
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?
[WebMethod]
public XmlDocument GetTileData(string user)
{
var xml = new XmlDocument();
xml.LoadXml(string.Format(@"<tile>
<visual>
<binding template='TileWideSmallImageAndText02'>
<image id='1' src='http://server/images/{0}_wide.png'/>
<text id='1'>Custom Field : {1}/text>
<text id='2'>Custom Field : {2}</text>
<text id='3'>Custom Field : {3}</text>
</binding>
<binding template='TileSquarePeekImageAndText01'>
<image id='1' src='http://server/images/{0}_square.png'/>
<text id='1'>Custom Field</text>
<text id='2'>{1}</text>
</binding>
</visual>
</tile>", value1, value2, value3, value4));
return xml;
}
Edit 1: I tried to return the Xml Element instead of the document, but it's not working either. I still see the declaration.
[WebMethod]
public XElement GetTileData(string user)
{
var xml = XDocument.Parse(string.Format(@"<tile>
<visual>
<binding template='TileWideSmallImageAndText02'>
<image id='1' src='http://server/images/{0}_wide.png'/>
<text id='1'>Custom Field : {1}/text>
<text id='2'>Custom Field : {2}</text>
<text id='3'>Custom Field : {3}</text>
</binding>
<binding template='TileSquarePeekImageAndText01'>
<image id='1' src='http://server/images/{0}_square.png'/>
<text id='1'>Custom Field</text>
<text id='2'>{1}</text>
</binding>
</visual>
</tile>", value1, value2, value3, value4));
return xml.Root;
}
Edit 2: I was able to get around this issue by using a HttpHandler. See my answer below.