我目前正在尝试使用 WCF 数据服务作为一种方式来更多地打开我们的产品,同时能够使用来自 AJAX 的数据。我注意到的一件事是 JSON 表示格式有这些 __metada 成员散布在数据中,在 OData 文档中我发现了这个(在 Representing Entries 下):
An optional "__metadata" name/value pair is the only pair that should be included on the object that does not directly represent a Property of the Entry being represented. This name/value pair is not data, but instead, by convention defined in this document, specifies the metadata for the Entry being represented.
我的问题是,如果此元数据是可选的,我该如何关闭它以节省带宽?
最佳答案
您是对的,WCF 数据服务服务器实现没有能力不发送 __metadata。协议(protocol)使其成为可选的事实并不意味着特定的实现不会总是发送它。在这种情况下,服务器会生成 __metadata,因为它可能包含客户端的重要信息,并且没有有效负载可能没有意义或提供不完整的信息。
目前服务器也没有提供任何选项来改变这种行为。
关于WCF 数据服务 : How to avoid the __metadata members,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3492706/