Why does my WCF service return and ARRAY instead of a List ?

后端 未结 3 1651
面向向阳花
面向向阳花 2020-12-10 12:44

In the web servce I say

 public List GetCustomers()
    {
        PR1Entities dc = new PR1Entities();
        var q = (from x in dc.Customers         


        
相关标签:
3条回答
  • 2020-12-10 13:23

    Because that's how a list serialises. Your Customer class on the client side has been generated from the service metadata, which effectively describes how it's serialised not how it was originally defined. If your original Customer class is available, you can specify to re-use it in the client code when you generate the service reference, and then it will come through as a List<T>.

    0 讨论(0)
  • 2020-12-10 13:25

    Right click on the service reference and select Configure Service Reference.

    In the Collection Type drop-down, select the type System.Collections.Generic.List.

    I believe the reason it defaults to Array is that it is the most compatible when serializing. If you're consuming the service from something that recognizes something more complex, you can configure as I mentioned.

    0 讨论(0)
  • 2020-12-10 13:32

    Right click on your service reference --> Configure Service Reference --> Under "Data Type" change "Collection Type" to System.Collections.ArrayList or whatever type you want the array to deserialize as.

    Your list is serialized into an array (server side). You choose how to deserialize it (client side).

    0 讨论(0)
提交回复
热议问题