OData is the bomb.
I just spent a few days creating a quick ASP.NET MVC3 website for a client. Nothing fancy, and thanks to MVC’s scaffolding the job was done quickly enough. Then the client asked me to create a web service so that another one of their systems could access it in the future.
Need you to write a simple API that allows us to query the job bag DB with an Job Number and return back the Client Ref (if available). Ideally – if you can extend out the API to return all data for a record we can use this for other things in the future also.
Come talk if you need more than this back of fag packet spec :)
Well, with 6 lines of code it was done. Right-click Web project, Add New Item, WCF Data Service.
public class JobService : DataService<JobSystemEntities>
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
config.SetEntitySetPageSize("*", 50); // limit to 50 rows
config.SetEntitySetAccessRule("Jobs", EntitySetRights.AllRead); // allow querying of all jobs e.g. http://localhost:34031/JobService.svc/Jobs
// config.SetEntitySetAccessRule("Jobs", EntitySetRights.ReadSingle); // need to specify a job e.g. http://localhost:34031/JobService.svc/Jobs(1001)
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
I used Jeff and Tim’s PDC10 screencast (which I linked to a few posts ago) as a reference on how to do this. (They add the OData service 45 mins in).
Too easy. Using that we can do all sorts of awesome queries, like: