问题
I have my dto defined as
[DataContract(Name = "Tuner", Namespace = "")]
public class TunerDto
{
[DataMember(Name = "TunerName", Order = 1)]
public string TunerName { get; set; }
}
and I am returning an array of theses which gives my XML in the body as:
<ArrayOfTuner>
<Tuner>
<Name>Test1</Name>
</Tuner>
...
</ArrayOfTuner>
Is there a way of replacing ArrayOfTuner with Tuners instead?
回答1:
You should wrap your array in a class, so you can add a [CollectionDataContract]
attribute to modify the serialization output:
[CollectionDataContract(ItemName = "Tuner")]
public class Tuners : List<TunerDto>
{
public Tuners() { }
public Tuners(IEnumerable<TunerDto> collection) : base(collection) { }
}
来源:https://stackoverflow.com/questions/10683732/service-stack-arrayof-to-be-removed