Moving from WCF Rest Starter Kit, CollectionDataContract doesn't work

Topics: Web Api
Sep 28, 2011 at 6:15 PM

Hey,

So - I'm totally loving the Web API awesomeness, but I have an issue. In the WCF REST Starter Kit, I was able to use CollectionDataContract to stop the xml output from containing "ArrayOf" nodes.

I'm trying to get:

<claims>
   <claim>
      ...
   </claim>
</claims>

Instead of:

<ArrayOfClaims>
   <claim>
      ...
   </claim>
</ArrayOfClaims>

It did work, and after switching over - I can't seem to get the same functionality. Anyone know of a way? I don't like the ugly "ArrayOf", and I'm trying to create a widely usable API here.

Coordinator
Sep 28, 2011 at 7:37 PM

By default WCF Web API uses the XmlSerializer for serializing to XML. If you prefer the DataContractSerializer you can configure it like this:

var config = new HttpConfiguration();

config.Formatters.XmlFormatter.UseDataContractSerializer = true;

From: djbyter [email removed]
Sent: Wednesday, September 28, 2011 10:15 AM
To: Daniel Roth
Subject: Moving from WCF Rest Starter Kit, CollectionDataContract doesn't work [wcf:274143]

From: djbyter

Hey,

So - I'm totally loving the Web API awesomeness, but I have an issue. In the WCF REST Starter Kit, I was able to use CollectionDataContract to stop the xml output from containing "ArrayOf" nodes.

I'm trying to get:

<claims>
<claim>
...
</claim>
</claims>

Instead of:

<ArrayOfClaims>
<claim>
...
</claim>
</ArrayOfClaims>

It did work, and after switching over - I can't seem to get the same functionality. Anyone know of a way? I don't like the ugly "ArrayOf", and I'm trying to create a widely usable API here.

Sep 28, 2011 at 7:53 PM

Perfect!