As developers know we cant return List
with web services, we can only return lists with converting them to .ToArray(); I\'ve searched some, but cant ge
Web services are supposed to be interoperable with many languages. Nearly all languages have arrays, but only .NET has the specific implementation of List<T>
that you're using.
As far as I am aware as long as you explicitly declare you are returning a List (of T) method title you can return the object; otherwise you will receive a serialize error.
e.g
<WebMethod()> _
Public Function Search(ByVal SearchTerm As String) As List(Of 'object here')
It depends on the interoperability settings of the webservice, an object like int[]
is easier to understand for a non .NET language then List<int>
. If you develop your web service under WCF, List<T>
is supported as a return type.
There is nothing whatsoever preventing you from returning List<T>
from an ASMX web service. I have no idea why you believe that.
What may be confusing you is that XML Schema (used by the WSDL) cannot describe "lists", per se. In fact, it cannot describe arrays, either. It can describe a series of repeating elements. All collections, including arrays, are returned as sets of repeating elements.
On the client side, the client has no way to know whether the server returned List<T>
, T[]
, or IEnumerable<T>
, and no reason to care, either.
What's described in the web services is a "collection". It's up to the client to determine what type of "collection" to use. If the client's .Net, when adding the service reference, click Advanced, and you'll have the ability to choose a generic list.