Hello,
I am trying to create a REST web service using .NET 4.0 and WCF. My REST service is returning a List which then gets serialized into XML. The problem I am having is that the XML being returned starts with ArrayOf, which I don't like.
In other words, right now the XML looks like this:
<ArrayOfAchievement>
<Achievement>
...
</Achievement>
</ArrayOfAchievement>
I would prefer to have the XML look like this:
<Achievements>
<Achievement>
...
</Achievement>
</Achievements>
If I create a new class and call it AchievementsList, which has a property of List< Achievement>, like so:
public class AchievementsList
{
public List<Achievement> Achievements { get; set; }
}
Then have my service return the above class instead of List< Achievement>, the XML ends up looking like this:
<AchievementsList>
<Achievements>
<Achievement>
...
</Achievement>
</Achievements>
</AchievementsList>
Which is wrong (because it adds another level that doesn't belong there).
The other problem is that I also need to apply a namespace to the object, like so:
[XmlRoot(Namespace="NameSpaceURL")]
public class AchievementsList
{
public List<Achievement> Achievements { get; set; }
}
Which I can't do if I just return a List< Achievement>.
So what can I do about these 2 problems?
Bara