Friday, October 17, 2008

Generating a proxy in WCF when generics is used

A weird problem we faced in our project was while generating a proxy class using Svcutil and WCF was returning a generics List using Visual Studio 2005 WCF extensions. An array was being generated for all the generic types.
By default svcutil command does not include System.Collection datatypes
By Default, the command is :
svcutil /l vb "http://localhost/SampleWCFService/SampleContract.svc?wsdl"
where SampleWCFService is a WCF service hosted on the IIS
If a service method returns or accepts a Generic List , then the svcutil command will be as follows :
svcutil /l vb /CollectionType:System.Collections.Generic.List`1 "http://localhost/SampleWCFService/SampleContract.svc?wsdl"
If the service accepts or returns more then one System.Collections datatypes,say, Hashtable and generic list then the command will be as follows :
svcutil /l vb /CollectionType:System.Collections.Hashtable /CollectionType:System.Collections.Generic.List`1 "http://localhost/SampleWCFService/SampleContract.svc?wsdl"

No comments: