kiran.p

I am not able to get the List<> data type.

The List<> are converted to array when we use

svcutil.exe http://<hostname/<servicename> wsdl for generating the client side CAO file and outputfile.

What i was curious to know is; why cannot WCF keep List<> as it is and not convert it to array.

Thanks in advance.

here is the sample code.

-------------------------------------Server side

//Decleration

namespace ConsoleApplication21

{

[DataContract]

public class Fields

{

[DataMember(Name="s1")]

internal string m_s1 = "";

[DataMember(Name="s2")]

internal string m_s2 = "";

}

}

//Interface

namespace ConsoleApplication21

{

[ServiceContract()]

public interface ICoreData3Service

{

[OperationContract]

List<Fields> getList();

}

}

//The Actual function

public class coredata3Service1 : ICoreData3Service

{

public List<Fields> getList()

{

Fields f1 = new Fields();

f1.m_s1 = "hello";

f1.m_s2 = "world";

Fields f2 = new Fields();

f2.m_s1 = "goodbye";

f2.m_s2 = "world";

List<Fields> lst = new List<Fields>();

lst.Add(f1);

lst.Add(f2);

return lst;

}

}

------------------------------------------------Client side

//The code that was generated had converted list<> into array

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]

[System.ServiceModel.ServiceContractAttribute(ConfigurationName="ICoreData3Service")]

public interface ICoreData3Service

{

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/ICoreData3Service/getList", ReplyAction=http://tempuri.org/ICoreData3Service/getListResponse)]

//List<> has been converted to array//List<> has been converted to array

ConsoleApplication21.Fields[] getList();

}

//Client side exection

namespace ConsoleApplication21

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine("Press enter when service is available...");

Console.ReadLine();

CoreData3ServiceClient client = new CoreData3ServiceClient();

//List<> has been converted to array

Fields[] lst = client.getList();

foreach (Fields field in lst)

{

Console.WriteLine("Field : {0} {1}", field.s1, field.s2);

}

Console.WriteLine("Press any key to kill...");

Console.ReadLine();

}

}

}



Re: Windows Communication Foundation (Indigo) how to generate List<> datatypes in wcf

Fabio Cozzolino

List<> is a specific type of .NET Framework and then WCF cannot expose them as is in the service metadata. Consequently WCF export them as a simple array.
This decouple the types defined in services and the types defined in the client application.

HTH





Re: Windows Communication Foundation (Indigo) how to generate List<> datatypes in wcf

kiran.p

Hi thanks for responding Smile

But we can expose custom data types right

So is there a way that we can treat List<> as a custom type, in shot any way of fooling WCF and making it think List<> is a custom type

thanks and regards

kiran





Re: Windows Communication Foundation (Indigo) how to generate List<> datatypes in wcf

Carlos Figueira - MSFT

You can use the /collectionType (short: /ct) option in svcutil.exe to specify the type used for collection types.

svcutil.exe http://<hostname/<servicename> wsdl /collectionTypeTongue Tiedystem.Collections.Generic.List`1

That will use the type List<T> for collections.





Re: Windows Communication Foundation (Indigo) how to generate List<> datatypes in wcf

kiran.p

Thanks for responding

I tried using this but at the client side i still get List<t> as array.. Sad

this is wat i used

" c:\> svcutil.exe http://localhost/Wcfservice1/myservice.scv wsdl /r:c:\windows\microsoft.net\

framework\v2.0.50727\System.dll /ctTongue Tiedystem.collections.Generic.List`1"

Am i doing some thing wrong





Re: Windows Communication Foundation (Indigo) how to generate List<> datatypes in wcf

Fabio Cozzolino

Try to use the simple form /rct, for the referenced collection type:

svcutil.exe http://localhost/Wcfservice1/myservice.scv wsdl /rctTongue Tiedystem.collections.Generic.List`1


bye