Saturday, May 9, 2009

Using Visual Studio 2008 Proxy Generation Tool to Create Custom Collections

The <CollectionMappings> section in the WCF mapping file (Reference.svcmap) allows you to specify your collection type to be generated via the Proxy when using the Visual Studio 2008 WCF Proxy generation tool.

E.g.: When creating application using WPF, I would really require my collections to be of ObservableCollection type rather than the List which my service method returns. I can force my Proxy Generation tool to create ObservableCollection types instead of Arrays by following the steps given below

1. Right Click Service Reference and Select Add Service Reference. Provide the service location details and generate the proxy.

2. Click Show All Files button on the solution explorer and expand the service reference and look for the Reference.svcmap file.

3. Under the <ClientOptions>node you will see <CollectionMappings>.Replace the contents to Map it to the System.Collections.ObjectModel.ObservableCollection as given below.

<CollectionMappings>

<CollectionMapping TypeName="System.Collections.ObjectModel.ObservableCollection`1" Category="List" />

CollectionMappings>

4. Right Click the service reference and select Update Service Reference.

You can follow the same approach for generating your custom collections instead of the ObservableCollection type.

No comments: