I manage my objects with a IoC-container (autofac). Because of that I only use interfaces instead of objects.
我用一个iocl容器(autofac)管理我的对象。因此我只使用接口而不使用对象。
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.
如果我的web api返回一个“Document”类型的对象,框架可以处理json和xml序列化。我向文档类添加了[DataContract]属性,但在接口中这是不可能的。
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.
如果我想返回一个IDocument类型的对象,我会得到一个HTTP-code 500。ASP。NET 4 MVC Web API现在是RC,框架还不能把接口成员序列化成xml吗?Json序列化没有问题。
0
The types exposed on the Web API interfaces must be DTOs - Data Transfer Objects. Also can be called ViewModels.
Web API接口上公开的类型必须是dto——数据传输对象。也可以称为ViewModels。
It is an anti-pattern to expose your Model on the client-agnostic Web API.
在与客户机无关的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.
如果您的API纯粹用于使用。net客户端,您可以使用WCF,也可以使用KnownType。在接口中也可以使用它们。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/06/11/60f702412c4e2571ac922a82cab60bd1.html。