I was wondering why I can't return an IEnumerable<T>
through a web service.
In my webservice I return an IEnumerable<T>
but when I check the IntelliSense in VS 2010 I see it's giving me a T[]
.
Can someone give me an explanation for this behaviour?
From MSDN:
Can I Use Generics in Web Services?
Unfortunately, no. Web services have to expose a WSDL-based contract. Such contracts are always limited by the expressiveness of the message format being used. For example, HTTP-GET based web services only support primitive types such as int or string, but not complex types like a DataSet. SOAP-based web services are more capable, but SOAP has no ability to represent generic type parameters. As a result, at present, you cannot define web services that rely on generic types. That said, you can define .NET web services that rely on closed constructed generic types, for example:
public class MyWebService
{
[WebMethod]
public List<string> GetCities()
{
List<string> cities = new List<string>();
cities.Add("New York");
cities.Add("San Francisco");
cities.Add("London");
return cities;
}
}
In the above example, List will be marshaled as an array of strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With