Unable to return custom class from WCF Data Service
-
Monday, October 04, 2010 3:19 AM
I am trying to return a custom class from my WCF data service. My custom class is:
[DataServiceKey("ID")] public class Applist { public int ID { get; set; } public string Name { get; set; } }
My data service looks like:
public static void InitializeService(IDataServiceConfiguration config) { config.RegisterKnownType(typeof(Applist)); config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetServiceOperationAccessRule("GetApplications", ServiceOperationRights.AllRead); } [WebGet] public IQueryable<Applist> GetApplications() { var result = (from p in this.CurrentDataSource.Applications orderby p.ApplicationName group p by p.ApplicationName into g select new Applist { ID = g.Min(p => p.id), Name = g.Key }); return result.AsQueryable(); }
However when I run the service, it gives me an error:
Request Error Request Error The server encountered an error processing the request. The exception message is 'Unable to load metadata for return type 'System.Linq.IQueryable`1[ApplicationService.Applist]' of method 'System.Linq.IQueryable`1[ApplicationService.Applist] GetApplications()'
The same query runs perfectly fine in LINQPad.
All Replies
-
Tuesday, October 05, 2010 12:35 AM
Hi,
Which version of the framework are you using? I tried it on 4.0 and it seems to work. Note that Applist will be treated as a complex type as it does not belong to any set.
Thanks,
-J
-
Tuesday, October 05, 2010 3:50 AMI am using VS 2008 3.5 with SP1. Basically its a ADO.Net Data Service
-
Tuesday, October 05, 2010 6:32 PMModerator
Can you trying installing the update? I remember we fixing some bugs in this area in this release.
Here's the link to the update: http://blogs.msdn.com/b/astoriateam/archive/2010/01/27/data-services-update-for-net-3-5-sp1-available-for-download.aspx
Once you install the update, this should work - the only thing is AppList will be a complex type instead of an entity type, since for a type to become an entity, it must be exposed via an entity set.
Hope this helps.
Thanks
Pratik
This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer by Pratik Patel - MSFTModerator Wednesday, October 06, 2010 4:42 PM
- Unmarked As Answer by SharePointGuy Monday, October 25, 2010 3:52 AM
-
Monday, October 25, 2010 3:52 AMI tried to install the update and tried again. But the same issue occurs. when I press F5, the data service returns "Error processing request". Any further help?
-
Monday, October 25, 2010 7:30 AMModerator
Hi,
What provider do you use for the rest of the data service? If it's EF, then I don't think this can work as the data service loads the metadata solely from the EF's CSDL file, and so if the type is not defined there, you can't use it.
Thanks,
Vitek Karas [MSFT] -
Monday, October 25, 2010 8:33 AMI have an edmx file that acts as a provider of data. In order to return custom class, can't I map m custom class with a custom entity defined in my EF edmx file? This way the csdl file will have my custom class defined. Thoughts?
-
Friday, November 12, 2010 7:55 AMHi, Have you managed to solve this problem?
Currently I'm getting the same error... I'm also using an edmx file with wcf...
Regards,
Annihil8 -
Friday, November 12, 2010 8:34 AMStill struggling. However my workaround was that I created a new project with .net 3.5 framework in VS 2010 and it worked fine. No idea why....?
-
Monday, July 25, 2011 11:22 AM
Hi Dude,
Did you solve this issue?
I got the same problem with you.
Can you help me?
I use .NET Framework 4.0 + VS 2010
Thanks in advance!!!!!!
-
Wednesday, March 14, 2012 3:24 PM
Same problem
framework 4 vs 2010

