WCF 服务操作不会将数据公开为可查询的
我有一个以下形式的服务操作:
[WebGet]
public IQueryable<BusinessObject> BusinessObjectsByType(string name)
使用访问规则
config.SetServiceOperationAccessRule("BusinessObjectsByType", ServiceOperationRights.All);
当我通过 Web 浏览器访问此服务操作时,它会公开数据,但不会以提要和条目(AtomPub 格式)形式公开数据,而且它也不让我使用 $top 等基本查询选项、 $orderby 等抱怨这些“无法应用于所请求的资源”。我已满足 http://msdn.microsoft.com/en 指定的所有要求-us/library/cc668788.aspx 但没有成功。任何帮助将不胜感激。谢谢。
I have a service operation of the form:
[WebGet]
public IQueryable<BusinessObject> BusinessObjectsByType(string name)
with access rule
config.SetServiceOperationAccessRule("BusinessObjectsByType", ServiceOperationRights.All);
When I access this service operation through a web browser, it exposes the data but not in feeds and entries (AtomPub format) and neither does it let me use basic query options like $top, $orderby, etc complaining that these 'cannot be applied to the requested resource'. I have matched all requirements specified at http://msdn.microsoft.com/en-us/library/cc668788.aspx but to no success. Any help will be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 BussinesObject 未被识别为实体,则服务操作将被视为返回 IEnumerable。为了使查询正常工作,服务操作必须返回 IQueryable,其中 T 是实体类型。
假设 EF 或 Reflection 提供程序的实体类型是具有键属性(通过启发式或通过 DataServiceKey 属性)的类型,并且在 IQueryable 类型的上下文类上有一个属性。
如果 BussinesObject 不是实体,则 WCF 数据服务无法支持对服务操作结果的查询。原因有很多,仅举一例:为了序列化响应,每个对象必须具有唯一的 URL(原子:id),为了能够生成唯一的 URL,对象必须具有关键属性。并且关键属性只能在实体上定义。
If the BussinesObject is not recognized as entity, the service operation will be treated as if returning IEnumerable instead. For the querying to work the service operation must return IQueryable where T is an entity type.
Assuming either EF or Reflection provider an entity type is a type which has a key property (either by heuristic or through DataServiceKey attribute) and for which there's a property on the context class of type IQueryable.
If the BussinesObject is not an entity, WCF Data Services can't support queries on the result of the service operation. There are many reasons, to name just one: in order to serialize the response each object must have a unique URL (it's atom:id), to be able to generate a unique URL the object must have key properties. And key properties can only be defined on entities.