I am writing a service to a international HTTP standard, and there is one method that can return three different XML results, call them Single, Multiple and Error. Now I've written an IXmlSerializable class that can consume each of these results and generate them. However, WCF seems to insist that I can only have a single return XML root name. I have to choose an XmlRoot for my custom object of either Single, Multiple or Error.
How can I set up WCF so that I can choose at runtime what the root will be?
This is what I have currently.
/// <summary>
/// A collection of items.
/// </summary>
[XmlRoot("Multiple", Namespace = "DAV:")]
public sealed class ItemCollection : IEnumerable<Item>, IXmlSerializable
/// <summary>
/// Processes and returns the items.
/// </summary>
[WebInvoke(Method = "POST", UriTemplate = "{*path}", BodyStyle = WebMessageBodyStyle.Bare)]
[OperationContract]
[XmlSerializerFormat]
ItemCollection Process(string path);
The ItemCollection implements IXmlSerializable and can choose which of the possible returns to write, however the root XML node is ALWAYS Multiple because of the XmlRoot attribute on the ItemCollection class.