开发者

Can't send generic list as a parameter to WCF method

I have a WCF service, in which one of the method(or operation contract) uses a generic list of certai开发者_JS百科n type as a parameter, however when i try to consume this service, and call this particular method i get this error

Cannot convert type 'System.Collections.Generic.List<CA.CCS.sCmd>' to 'CA.CCS.sCmd[]'

I don't know why an object array is expected instead of a generic list in the consumer code.

I want to send that parameter as generic list only, without any conversions on client or server, since it hampers the service performance.

I have found similar questions on stack overflow, but none solving my problem.

your response, or link to other's response will be greatly appreciated.

Update : I get this window when i try to add service reference, can't find any settings here

Can't send generic list as a parameter to WCF method


Because you're still using VS2005, and your proxy generator apparently wants to turn this into an array parameter, you'll just have to convert your List<T> to a T[] whenever you call this method.

Since you have a List<T> instance, you can just use its ToArray method (supported since .NET 2.0). So instead of calling SomeMethod(myList), you can do SomeMethod(myList.ToArray()).


I want to send that parameter as generic list only, without any conversions on client or server, since it hampers the service performance.

There's something I don't understand here: You call a WCF service so either you're misusing it to send large amounts of data or there is no performance problem. Besides, I think you're overworried about performance here. What kind of performance issue do you expect? Even if you have a very large list: If it contains only reference types the array is just a list of smaller pointers. Only if you have a large amount of structs or other value types there will be performance issues, but still a list of 10,000 double values uses only about 80kb memory.

And if you type this code:

List<int> myList = new List<int>();
for (int i = 0; i < 10000; i++)
  myList.Add(i);

you've probably coded a bigger performance issue.

Unless you have more information on what could create a problem I'd say use ToArray() and be done.


specific collection type information is lost in metadata while exported to wsdl, in other words collections send between service and consumers are represented as array. You can visit this page and go to 'Customizing Collection Types' section to see how create a custom collection and expose it in contract or see this tutorial

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜