Reputation: 5153
I am having trouble when using List objects:
[DataContract]
public class Recipe
{
[DataMember(Name="Allergies")]
public List<AllergyModel> Allergies { get; set; }
}
[DataContract]
public class AllergyModel
{
public string Allergy { get; set; }
}
How do I make the XML produced not include the AllergyModel node? When I come to read the Recipe parameter, the Allergies list property is null because in the original XML the structure does not have the AllergyModel node.
<Allergies>
<a:AllergyModel>
<a:Allergy>nuts</a:Allergy>
</a:AllergyModel>
<a:AllergyModel>
<a:Allergy>wheat</a:Allergy>
</a:AllergyModel>
</Allergies>
Upvotes: 2
Views: 1277
Reputation: 547
You can use MessageContract attribute instead and set the IsWrapped parameter to false
Upvotes: 1
Reputation: 364389
Try to use custom collection instead:
[CollectionDataContract(Name = "Allergies", ItemName = "Allergy")]
public class AllergyList : List<string>
{
...
}
Use this collection instead of List<AllergyModel>
. The important is that you can pass the name of the item in the custom collection.
Upvotes: 3