OData Service Operations in JayData – Calling server methods with JavaScript

Author: Peter Aron Zentai May 11th, 2012

, , , ,

As of RC1 Refresh 1 you can use service operations (server side functions) with JayData. To create one and then consume it with JavaScript is just a matter of minutes and a couple of line of codes – with the right tools in hand.

OData Service Operations provide a powerful way of exposing data with maximum control over the data given out.

As usual the JayDataNorthwind sample project will be used as a base for the examples below.

Create Service Operation with WCF Data Service

Our sample will limit the number of the results to a maximum 5 and also enforces that some price filtering is applied.

Generate Northwind.js

Using the JaySvcUtil.exe command line tool generate Northwind.js from the metadata exposed by the WCF Data Service.

Call GetBudgetProducts from JavaScript

Our newly forged server method appears in the intellisense list with parameter hint


Service Operations behave like EntitySets!

Service calls due to their asynchronic nature does not return their value. Instead they accept a handler method or return a promise to an array of values.

Handler method way


This is what goes to the server in the form of a http request


If you don’t like the handler methods way or need to handle multiple async requests in a simple way then you can treat the toArray() result as a so called promise. JayData does not have a Promise implementation rather it defines a promise interface. A default promiseimplementation with the jQuery.deferred library is included in the JayData library and is set as default.

Using results as promises


, , , ,