views:

36

answers:

1

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.

A: 

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.

Vitek Karas MSFT
Thanks for your pointers Vitek. I have double-checked everything you mentioned above. To validate what I am doing, I created another data service for an entity list and made sure I'm able to query the response available in the form of feed and entries. However, when I converted this data service to a service operation, the response was not queryable. I wonder if this has anything to do with the fact that I'm on .Net 3.5 and Visual Studio 2008.
Nitesh Baranwal
Do you have the latest update for WCF Data Services? http://blogs.msdn.com/b/astoriateam/archive/2010/01/27/data-services-update-for-net-3-5-sp1-available-for-download.aspx(I don't know if that will fix it though).If you could share the output of your $metadata endpoint it might help to understand the problem better.
Vitek Karas MSFT
OK, I caught my mistake. I was removing the access rule for entity when creating a service operation. Didn't quite realize I still had to expose the entity property in service.
Nitesh Baranwal