1

I have succesfully implemented a RESTful Web Service using the .NET 4.0 framework with MVC 4 and the ApiController class. I have a method, let's say GetMovies ("/api/movies") that returns an IQueryable<Movie>. Serialization is done using DataContractSerializer, of course. The problem is in the name of the returned list, because it is ArrayOfMovie:

<ArrayOfMovie>
    <Movie></Movie>
    <Movie></Movie>
    ...
    <Movie></Movie>
</ArrayOfMovie>

I cannot create a custom class, let's say Movies, and add a [CollectionDataContract(Name = "movies")] annotation (as suggested at https://stackoverflow.com/a/4593167/801065) because I cannot extend IQueryable without implementing all of its methods. And I most definitely need an IQueryable for OData/jQuery processing. How can I solve this? Is there an annotation that can help me?

Community
  • 1
  • 1
frapontillo
  • 10,499
  • 11
  • 43
  • 54

1 Answers1

0

This is the solution I found. You need to put a group class in the main class you want to serialize.

[DataContract(Name = "movies")]
public class group
{
    [DataMember(Name="movies")]
    public IQueryable<Movie> Movies;
}
frapontillo
  • 10,499
  • 11
  • 43
  • 54