InfiniTec - Henning Krauses Blog

Don't adjust your mind - it's reality that is malfunctioning

Visual Studio 2008 WCF proxy generation tool and the ObservableCollection

Visual Studio 2008 has a nice WSDL generator for WCF services. Among other things, one nice feature is it's ability to generate strongly-typed lists (List<T> in C#) where the Visual Studio 2005 service proxy generator would have generated arrays. But there's more: The configuration program let's you actually choose the type of list to implement:


The WCF service configuration editor (click to enlarge)

Since I'm using WPF here I badly missed one list in the available dropdown: The ObservableCollection<T>.

But it turns out that you can force the configuration editor to generate a service proxy using the ObservableCollection<T> for arrays: Just hit the "Show all files" button in the solution explorer and navigate to your WCF reference, expand the node and open the file called Reference.svcmap. It's an XML file containing the settings for the proxy generation tool. And this file contains a tag called CollectionMapping. If you have previously changed the collection mapping with the editor, you'll find your settings there. For the above selection of the standard generic List, you'll find an entry like this:

    1 <CollectionMappings>

    2   <CollectionMappingTypeName="System.Collections.Generic.List`1"Category="List" />

    3 </CollectionMappings>

If you change the TypeName attribute from System.Collections.Generic.List`1 to System.Collections.ObjectModel.ObservableCollection`1 the service proxy generation tool will use ObservableCollections in the next update. And the configuration editor will just show a (Custom) in the drop-down, so you can still use it to modify the other settings.


Technorati:

Posted by Henning Krause on Monday, August 13, 2007 12:00 AM, last modified on Tuesday, August 14, 2007 12:00 PM
Permalink | Post RSSRSS comment feed

Comments (2) -

On 7/18/2008 10:25:28 PM Luke United States wrote:

Luke

Awesome! This totally fixed what I was trying to do.

On 12/1/2008 9:23:02 PM Ben Iffland New Zealand wrote:

Ben Iffland

Hi. Do you know if there is a way to have multiple collection types in WCF. e.g. I want to have a List&amp;lt;Collection&amp;gt; where List is a generic list and Collection is an actual Collection type (rather than a generic List)?