O'Reilly logo

Microsoft Windows Communication Foundation 4.0 Cookbook for Developing SOA Applications by Steven Cheng

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Returning ReadOnlyCollection data

It is quite common to return a collection of data objects in a WCF service operation. However, sometimes we need to return a list of objects that are stored in the ReadOnlyCollection<T> type instance. This cannot be done directly, since ReadOnlyCollection<T> is not supported by the WCF DataContractSerializer. To make a WCF service operation return an ReadOnlyCollection<T> collection, we need to perform some customization on the OperationContract.

How to do it...

To return ReadOnlyCollection<T> collection instances, we need to modify our WCF service operation's OperationContract—the return type should be changed to use a base/generic Collection type other than ReadOnlyCollection<T>. For example, in our sample service, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required