Few weeks ago i was training our offshore team on WCF and WSSF. while the guys were doing hands on, they had noticed that the Generic List what they were returning from WCF service was converted to Array and they had no clue why it was happening.

Answer :

Because web services / WCF Service are platform-agnostic, they need to use the most primitive data types. 

Scenerio 1 :

 what would happen if your web service would be consumed by a .NET 1.x application, where no generics are available.

Scenerio 2 :

How would non .Net applications (J2ee or PHP) will consume the service, which doenst have the knowledge of .Net Generics?

The convertion happens because array is the lowest common denominator.

Is that means that we shouldn't be using generic List<T> in the service, the answer is yes you should :-), Because the Native .net applications can take advantage of the Generic List<T> like windows form application in .Net version 2.0 and above

Note : The webservice / WCF service proxy's are generated on the fly based on the nature of the client your using with. if you use them with Windows Form application you will still see the proxy generated will be with the List objects. where us if you use it in ASP.net application the same interface will be generated with Array.

Happy Programming !!!

posted on Friday, January 25, 2008 1:02 AM
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Comments

Gravatar
# re: .Net Generic List gets converted to Array when exposed to the WCF client
posted by Simon Cooper
on 4/12/2010 10:47 AM
thank you this was helpful to me

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: