Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array vs List for interoperability purposes with WCF

Tags:

arrays

list

wcf

I have taken up a WCF project which has the convention of returning data in Arrays as opposed to Lists. I was told that the reason for this is to improve potential interoperability with non .NET consuming applications.

Are there any good examples that illustrate that it is worth returning Arrays from a WCF service instead of Lists?

like image 346
lockstock Avatar asked Apr 12 '12 23:04

lockstock


2 Answers

I previously worked on a project with the same implementation, and the same reasoning. I was unable to get a valid explanation from any of the project team.

I'd like to hear a justification, but until I do I don't believe this.

Both Array and a List serialize as a collection in XML or JSON - there is no difference, because these are interoperable and functionally null languages. Note that when you use the 'Add Service Reference...' tool in Visual Studio, you have the option of using a List or an Array as your collection type.

If you use a binary serialization in WCF then there will be a difference between List and Array, but binary serialization only works from .NET to .NET so there is no potential for interoperability issues.

like image 187
Kirk Broadhurst Avatar answered Nov 08 '22 12:11

Kirk Broadhurst


Remember that web services don't return arrays. They also don't return lists. They return XML.

The XML for an array is identical to the XML for a list.

like image 43
John Saunders Avatar answered Nov 08 '22 14:11

John Saunders