Windows Vista Forums
Vista Forums Home Join Vista Forums Tech Publications Windows 7 Forum Vista Tutorials Webcasts Tags

Welcome to Vista Forums we are your forum for Windows Vista help and discussion. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > WinFX General

WCF converts List<string> to string[]

Update your Vista Drivers
 
 
Thread Tools Display Modes
Old 10-30-2006   #1 (permalink)
John
Guest


 

WCF converts List<string> to string[]

I'm having a problem passing List<T> from a service. I don't know if the
problem is at the service or the client. For some reason a List is getting
converted to an array. Here are the details:

I have a simple type called SimpleType that contains a List:

[DataContract]
public class SimpleType
{
[DataMember]
public List<string> Strings
{
get { return strings; }
set { strings = value; }
}
private List<string> strings;
}

The service code is equally simple:

public SimpleType GetSimpleType()
{
return new SimpleType();
}

The client creates the following code for SimpleType's List:

[System.Runtime.Serialization.DataMemberAttribute()]
public string[] Strings
{
get
{
return this.StringsField;
}
set
{
this.StringsField = value;
}
}

Is there something I need to do to have a List created at the client rather
than an array? Is there a property I forgot to set somewhere?

Thanks,
John



My System SpecsSystem Spec
Old 10-31-2006   #2 (permalink)
Chris Mullins
Guest


 

Re: WCF converts List<string> to string[]

"John" <revelation@nospam.nospam> wrote
> I'm having a problem passing List<T> from a service.


> [DataMember]
> public List<string> Strings
> {
> get { return strings; }
> set { strings = value; }
> }


If nothing else, this code won't pass any of the Static Code Analysis tools.
You should be exposing the IList<> interface, or one of the
System.Collections.ObjectModel collections. Requiring things via your
interface (especially one exposed on the web) to be an actual List<> class
is bad form.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins


My System SpecsSystem Spec
Old 10-31-2006   #3 (permalink)
John
Guest


 

Re: WCF converts List<string> to string[]

Thank you for the critique, Chris. This was only a simple example to
demonstrate the problem I'm having. But I welcome any constructive advice
you can provide. If you can recommend some good material on the subject I
would appreciate it. But now back to my problem...

I've tried List<>, IList, ArrayList and even
System.Collections.ObjectModel.Collection. In all cases the client builds a
proxy containing a simple array. I would like it to create something more
useful than an array. Is that possible?

John


"Chris Mullins" <cmullins@yahoo.com> wrote in message
news:uXzJpzS$GHA.1168@TK2MSFTNGP03.phx.gbl...
> "John" <revelation@nospam.nospam> wrote
>> I'm having a problem passing List<T> from a service.

>
>> [DataMember]
>> public List<string> Strings
>> {
>> get { return strings; }
>> set { strings = value; }
>> }

>
> If nothing else, this code won't pass any of the Static Code Analysis
> tools. You should be exposing the IList<> interface, or one of the
> System.Collections.ObjectModel collections. Requiring things via your
> interface (especially one exposed on the web) to be an actual List<> class
> is bad form.
>
> --
> Chris Mullins, MCSD.NET, MCPD:Enterprise
> http://www.coversant.net/blogs/cmullins
>
>



My System SpecsSystem Spec
Old 07-17-2008   #4 (permalink)
Newbie


Join Date: Jul 2008
Windows XP
 
Rep Power: 3
Frederico.Almeida is on a distinguished road
  Frederico.Almeida is offline

Re: WCF converts List<string> to string[]

My System SpecsSystem Spec
 
Update your Vista Drivers

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a string within a variable string Edward.A.Gonzalez PowerShell 4 08-15-2008 09:13 AM
Fast way to determine if a string contains a member of a list of strings Karch .NET General 15 03-06-2008 05:07 PM
problems with $var | select-string -pattern $string -q Ben Christian PowerShell 3 02-08-2008 01:41 PM
How export-csv deals with string versus string[] Marco Shaw PowerShell 2 07-13-2007 01:18 PM
String PRODUCT_NAME was not found in string table Extracampine Vista General 3 02-12-2007 07:15 AM


Complimentary Industry Resources

Vista Forums has joined forces with TradePub.com to offer you a new, exciting, and entirely free professional resource. Visit http://vistax64.tradepub.com today to browse our selection of complimentary Industry magazines, white papers, webinars, podcasts, and more across 34 industry sectors. No credit cards, coupons, or promo codes required. Try it today!




Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51