Different return XML in a WCF Operation
Posted
by Sean Hederman
on Stack Overflow
See other posts from Stack Overflow
or by Sean Hederman
Published on 2010-05-13T13:49:39Z
Indexed on
2010/05/13
13:54 UTC
Read the original article
Hit count: 310
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);
© Stack Overflow or respective owner