I manage my objects with a IoC-container (autofac). Because of that I only use interfaces instead of objects.
If my web api returns a object of type “Document” the framework can handle json and xml serialization.
I added [DataContract]-Attributes to the Document-class, but in a interface this is no possible.
So if i want to return a object of type IDocument, i get a HTTP-code 500.
ASP.NET 4 MVC Web API is now RC, can the framework still not serialize interface member into xml?
Json serialization is no problem.
The types exposed on the Web API interfaces must be DTOs – Data Transfer Objects. Also can be called ViewModels.
It is an anti-pattern to expose your Model on the client-agnostic Web API.
If your API is purely for the consumption of the .NET clients, either you can use WCF or you may use KnownType. It should be OK to use them with interface as well.