0

I have a REST web service that returns a structure containing an array of more structures. This return structure looks like this:

[DataContract]
public class Response {
  private ResponseRecord[] m_Record;

  [DataMember]
  public int TotalRecords { get; set; }

  [DataMember]
  public ResponseRecord[] Record {
    get { return m_Record; }
    set { m_Record = value; }
  }
}

The ResponseRecord class is like this:

[DataContract(Name="Record")]
public class ResponseRecord {
  [DataMember(Order = 0)]
  public string RecordID { get; set; }
/* Many more objects */
}

My web service returns XML like this:

<Response>
  <TotalRecords>1</TotalRecords>
  <Record>
    <ResponseRecord>
      <RecordID>1</RecordID>
      ... Many more objects ...
    </ResponseRecord>
  </Record>
</Response>

What I would like to do is get rid of that "ResponseRecord" hierarchal level, as it adds no new information. This web service also runs for SOAP and XML, and the (Name="Record") attribute did the trick. Not so for REST for some reason, though. Why?

2 Answers 2

1

First of all, I suggest you change Record property to Records as records is really what it is.

Also, if you remove ResponseRecord, there won't be anything to group the properties of each ResponseRecord instance together. So it is not possible.

Sign up to request clarification or add additional context in comments.

1 Comment

I think I meant to say that I wanted to get rid of the <Record> level. Is this possible?
0

Turns out my array was set up incorrectly:

[DataContract]
public class Response {
  private ResponseRecord[] m_Record;

  [DataMember]
  public int TotalRecords { get; set; }

  [System.Xml.Serialization.XmlElementAttribute("Record")]   // <-- HERE
  public ResponseRecord[] Record {
    get { return m_Record; }
    set { m_Record = value; }
  }
}

This removed the ResponseRecord level, which is what I wanted gone.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.