lockstock
lockstock

Reputation: 2437

Array vs List for interoperability purposes with 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?

Upvotes: 10

Views: 2693

Answers (2)

John Saunders
John Saunders

Reputation: 161821

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.

Upvotes: 7

Kirk Broadhurst
Kirk Broadhurst

Reputation: 28738

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.

Upvotes: 11

Related Questions