Using Generic List<T> From WCF Services - Hilton Giesenow's Jumbled Mind

Hilton Giesenow's Jumbled Mind

the madness that is...

News

This is my little spot in cyberspace where you will find a collection of random (but mostly software-related) thoughts and ideas that are frightening in their shining brilliance (or something like that ;->).
 
Please enjoy your stay and feel free to Contact Me.
 
Microsoft MVP

.Net Links

BlogRoll

Misc. Links

Syndication

Using Generic List<T> From WCF Services

I've had a lot of traffic to a post from a while back on "Make Your Web Service Proxies Return List<T> Using RegEx (And The Regulator)". In the post, I was converting the arrays that were being generated by the web client proxy into List<T> (Or List(Of T) if you speak VB) and I was using RegEx to do. It was a bit tricky because I had to ignore the object[] arrays that were being used internally in the proxy class and it was a bit kludgy because it had to be run by hand every time you updated the proxy. Later on, I had a follow up for WCF proxies, but it required you to generate your proxy via the command line.

With Visual Studio 2008 and WCF, these problems go away, but you've got to know how to do it. VS 2008 no longer offers an "Add Web Reference" option - it only gives you an "Add Service Reference" (at least that's if you're using a .net 3.0 or later project) which generates a WCF proxy. When you add a service proxy reference, the trick is to open up the Advanced Options:

AddServiceReference

On the window that loads up, there is a "Collection type" setting (and a "Dictionary collection type" as well if you need that). On this drop down list, simply chance the type to System.Collections.Generic.List:

ServiceReferenceSettings

Updating an Existing Service Reference

If you've already got an existing service reference and you want to change it now to using a List<T>, right click on it and select Configure Service Reference:

ConfigureServiceRefernce

When you do this, a window similar to the Service Reference Settings window from above appears, allowing you to do the same as before:

ServiceReferenceSettings - Update

Posted: May 21 2008, 03:47 PM by hiltong | with 3 comment(s)
Filed under: ,

Comments

hiltong said:

You can't really, but it's important to understand why. Conceptually, the only things a client has access to are the types that can be represented in WSDL. The feature above just allows access to more advanced .net types so that you can use their features more easily. Here's an important question - is this just a useful collection type you want to use in the client, or is it something specific that you use on the server side too?

# July 1, 2008 9:10 PM

Faheem Ahmad said:

Really  very useful

# September 26, 2008 6:57 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: