简体   繁体   中英

How to change element name in C# REST service post call

I have aa REST interface method:

[DataContract(Namespace = "")]
public class SEPTABLINE
{
    [DataMember(Order = 0)]
    public string LGNUM;
    [DataMember(Order = 1)]
    public string LABOR;
    [DataMember(Order = 2)]
    public string MATNR;
    [DataMember(Order = 3)]
    public string ACTIVE;
    [DataMember(Order = 4)]
    public string MAX_DAYS;
}

[OperationContract]
[WebInvoke(UriTemplate = "SEPTAB", Method = "POST")]
Stream AddSEPTAB(List<SEPTABLINE> separationTabLines);

To call this method I have to use the following structure:

<ArrayOfSEPTABLINE>
  <SEPTABLINE>
    <LGNUM>String content</LGNUM>
    <LABOR>String content</LABOR>
    <MATNR>String content</MATNR>
    <ACTIVE>String content</ACTIVE>
    <MAX_DAYS>String content</MAX_DAYS>
  </SEPTABLINE>
  <SEPTABLINE>
    <LGNUM>String content</LGNUM>
    <LABOR>String content</LABOR>
    <MATNR>String content</MATNR>
    <ACTIVE>String content</ACTIVE>
    <MAX_DAYS>String content</MAX_DAYS>
  </SEPTABLINE>
</ArrayOfSEPTABLINE>

How can I change the name ArrayOfSEPTABLINE to SEPTAB? Or is it possible to change the call to

  <SEPTABLINE>
    <LGNUM>String content</LGNUM>
    <LABOR>String content</LABOR>
    <MATNR>String content</MATNR>
    <ACTIVE>String content</ACTIVE>
    <MAX_DAYS>String content</MAX_DAYS>
  </SEPTABLINE>
  <SEPTABLINE>
    <LGNUM>String content</LGNUM>
    <LABOR>String content</LABOR>
    <MATNR>String content</MATNR>
    <ACTIVE>String content</ACTIVE>
    <MAX_DAYS>String content</MAX_DAYS>
  </SEPTABLINE>

without the ArrayOfSEPTABLINE?

I am not sure but you should try this

public class StreamList
{
    [DataMember]
    public List<Stream> Stream;
}

[OperationContract]
[WebInvoke(UriTemplate = "SEPTAB", Method = "POST")]
StreamList AddSEPTAB(List<SEPTABLINE> separationTabLines);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM