03 May, 2010

Solution Array for List in WCF

Here is another common problem encounters with WCF Service in initial days. Suppose there is a method which returns a List of Objects the proxy will be generated as method which returns an array of objects.
Reason:
This problem is due to the default interpretation of collections. While generating proxy for the service all the collections are by default interpreted as arrays. That is why all the lists will be converted to arrays.
Solution:
If you are generating proxy by adding service reference from visual studio directly, there will be a 'advanced' button. Click that button and select the System.Generic.List as your Collection. This will resolve the problem.
If you are generating proxy with svcutil here is the command to do the job.
svcutil.exe http://ServerName/ServiceName/Servic.svc?wsdl /collectionType:System.Collections.Generic.List`1
or in short svcutil http://ServerName/ServiceName/Servic.svc?wsdl /ct:System.Collections.Generic.List`1

for more information go through this link http://msdn.microsoft.com/en-us/library/aa347733.aspx
Here is a post which describes the basics of creating wcf service http://sivakrishnakuchi.blogspot.com/2010/05/how-to-create-wcf-service-application.html

1 comment:

  1. Does this solution support for .NETCF (netcfsvcutil.exe)?

    if not how could I get solution for netcf

    thanks to advice

    ReplyDelete