Skip to Content
Programming WCF Services, 2nd Edition
book

Programming WCF Services, 2nd Edition

by Juval Lowy
November 2008
Intermediate to advanced
784 pages
23h 28m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services, 2nd Edition

Collections

In .NET, a collection is any type that supports the IEnumerable or IEnumerable<T> interface. All of the built-in collections in .NET, such as the array, the list, and the stack, support these interfaces. A data contract can include a collection as a data member, and a service contract can define operations that interact with a collection directly. Because .NET collections are .NET-specific, WCF cannot expose them in the service metadata, yet because they are so useful, WCF offers dedicated marshaling rules for collections.

Whenever you define a service operation that uses the collection interfaces IEnumerable<T>, IList<T>, or ICollection<T>, the resulting metadata always uses an array. For example, this service contract definition and implementation:

[ServiceContract]
interface IContactManager
{
   [OperationContract]
   IEnumerable<Contact> GetContacts(  );
   ...
}
class ContactManager : IContactManager
{
   List<Contact> m_Contacts = new List<Contact>(  );

   public IEnumerable<Contact> GetContacts(  )
   {
      return m_Contacts;
   }
   ...
}

will be exported as:

[ServiceContract]
interface IContactManager
{
   [OperationContract]
   Contact[] GetContacts(  );
}

Concrete Collections

If the collection in the contract is a concrete collection (not an interface) and is a serializable collection—that is, it is marked with the Serializable attribute but not with the DataContract attribute—WCF can normalize the collection automatically to an array of the collection's type, provided the collection contains an Add( ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services

Programming WCF Services

Juval Lowy

Publisher Resources

ISBN: 9780596157210Supplemental ContentErrata