Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF: XmlSerialization attribute ignored for the root element
    text
    copied!<p>I'm working on a REStful WCF service that returns XML generated by the XML Serializer (as opposed to the <code>DataContract</code> serializer).</p> <p>Whilst most objects are formatted correctly, the root element of what is returned seems to be ignoring my XML serialization attributes.</p> <p>For example, the resource <code>/accounts/</code> returns an XML serialized representation of my AccountList class (itself a subclass of my own <code>ObjectList&lt;T&gt;</code> class which has some properties on it that should be serialized). However I'm not getting the results I want.</p> <p>Here is my code:</p> <pre class="lang-cs prettyprint-override"><code>[XmlRoot("accounts")] public class AccountList : ObjectList&lt;Account&gt; { } public class ObjectList&lt;T&gt; : List&lt;T&gt; { [XmlAttribute("foo")] public Int32 FooProperty { get; set; } } [OperationContract] [WebGet(UriTemplate="/accounts")] public AccountList GetAccounts() { return new AccountList() { new Account("bilbo baggins"), new Account("steve ballmer") }; } </code></pre> <p>And this is what is returned by the web service:</p> <pre><code>&lt;arrayOfAccount&gt; &lt;Account&gt; &lt;name&gt;biblo baggins&lt;/name&gt; &lt;/Account&gt; &lt;Account&gt; &lt;name&gt;steve ballmer&lt;/name&gt; &lt;/Account&gt; &lt;/arrayOfAccount&gt; </code></pre> <p>So the main problem is that my desired serialization on the AccountList class is being ignored, and I'd also like to know how to get it so "Account" is in lowercase like the "name" property is (I used [XmlElement("name")] on those properties and it works fine.</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload