Skip to Content
Programming WCF Services
book

Programming WCF Services

by Juval Lowy
February 2007
Intermediate to advanced
634 pages
16h 1m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services

Collections

In .NET, a collection is any type that supports the IEnumerable or IEnumerable<T> interfaces. 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, or 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’re defining a service operation that uses any of the following collection interfaces: IEnumerable<T>, IList<T>, and ICollection<T>, the wire representation 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 ...

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, 2nd Edition

Programming WCF Services, 2nd Edition

Juval Lowy
Pro WCF: Practical Microsoft SOA Implementation

Pro WCF: Practical Microsoft SOA Implementation

Chris Peiris, Dennis Mulder, Shawn Cicoria, Amit Bahree, Nishith Pathak
Mastering ASP.NET Web API

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Publisher Resources

ISBN: 0596526997Supplemental ContentErrata Page