Why can't we return List <T> to ASMX web services?

Since developers know that we cannot return List<T> using web services, we can only return lists with their conversion to .ToArray (); I have been looking for some, but cannot get an effective answer on why we cannot reconfigure the list using web services. Why should we convert them to Toray ();

+4
source share
5 answers

Web services are assumed to be compatible with many languages. Almost all languages ​​have arrays, but only .NET has the specific List<T> implementation that you use.

+9
source

Nothing prevents you from returning a List<T> from the ASMX web service. I have no idea why you believe this.

What may confuse you is that the XML schema (used by WSDL) cannot describe lists as such. In fact, it also cannot describe arrays. 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 of knowing whether the server returned List<T> , T[] or IEnumerable<T> , and there is no reason to worry.

+5
source

It depends on the interaction parameters in the web service, so an object such as int[] is easier to understand for a non-.NET language and then List<int> . If you are developing your web service under WCF , List<T> supported as a return type.

+2
source

What is described in web services is a “collection”. It is up to the client to determine which type of “collection” to use. If the client .Net, adding a link to the service, click "Advanced", and you will have the opportunity to select a common list.

+1
source

As far as I know, as long as you explicitly declare that you are returning the name of the List (of T) method, you can return an object; otherwise, you will get a serialization error.

eg

 <WebMethod()> _ Public Function Search(ByVal SearchTerm As String) As List(Of 'object here') 
0
source

All Articles