0

I have a WCF service to return customer data. An arraylist is created by adding a new instance of an object. The code looks like this:

objCust.CUSTNUM  = CustomerByNumber_CST#9A
objCust.CUSTNAME = CustomerByNumber_NAME9A
objCust.CUSTADR1 = CustomerByNumber_ADR19A
objCust.CUSTADR2 = CustomerByNumber_ADR29A
objCust.CUSTCITY = CustomerByNumber_CITY9A
objCust.CUSTSTAT = CustomerByNumber_STAT9A
objCust.CUSTZIP  = CustomerByNumber_ZIPC9A
objCust.CUSTPHON = CustomerByNumber_PHON9A

aryList.Add(objCust)

I then return the array list as an array - aryList.ToArray(...

When I call the service, the array elements come back sorted in alphabetical order - here is the output:

<b:CUSTADR1>3910 LAKEFIELD DR</b:CUSTADR1>
<b:CUSTADR2>JOHNS CREEK FACILITY</b:CUSTADR2>
<b:CUSTCITY>SUWANEE</b:CUSTCITY>
<b:CUSTNAME>JOHNSON CONTROLS</b:CUSTNAME>
<b:CUSTNUM>1688</b:CUSTNUM>
<b:CUSTPHON>770-495-9950</b:CUSTPHON>
<b:CUSTSTAT>GA</b:CUSTSTAT>
<b:CUSTZIP>30024</b:CUSTZIP>

I'm not doing any sorting. Why is this sorted? I'd like it to be in the order that I added them.

Brian
  • 548
  • 2
  • 8
  • 22

1 Answers1

0

WCF data contract serializers sort object properties unless you provide a specific order numeric value in the DataMemberAttribute declaration. It has nothing to do with arrays and would happen even if you return a single object.

Dmitry S.
  • 8,373
  • 2
  • 39
  • 49