How can I define a [OperationContract] [WebGet] method to return XML that is stored in a string, without HTML encoding the string?
The application is using WCF service to return XML/XHTML content which has been stored as a string. The XML does not correspond to any specific class via [DataContract]. It is meant to be consumed by an XSLT.
[OperationContract]
[WebGet]
public XmlContent GetContent()
{
return new XmlContent("<p>given content</p>");
}
I have this class:
[XmlRoot]
public class XmlContent : IXmlSerializable
{
public XmlContent(string content)
{
this.Content = content;
}
public string Content { get; set; }
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
throw new NotImplementedException();
}
public void WriteXml(XmlWriter writer)
{
writer.WriteRaw(this.Content);
}
#endregion
}
But when serialized, there is a root tag the wraps the given content.
<XmlContent>
<p>given content</p>
</XmlContent>
I know how to change the name of the root tag ([XmlRoot(ElementName = "div")]), but I need to omit the root tag, if at all possible.
I have also tried [DataContract] instead of IXmlSerializable, but it seems less flexible.