We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DataManager with WCF-RESTful Example

Can I have an example about how-to use DataManager consume WCF-RESTful with and without parameter?



2 Replies

MS Madhu Sudhanan P Syncfusion Team April 28, 2014 12:57 PM UTC

Hi Simla,

 

Currently we are working in your requirement and we will update you the response on April 29, 2014.

 

Please let us know if you have any queries.

 

Regards,

Madhu Sudhanan. P



MS Madhu Sudhanan P Syncfusion Team April 29, 2014 05:07 PM UTC

Hi Simla,

 

Thanks for using Syncfusion products.

 

Based on your request, we have created a simple Grid sample which is loaded with the data from the WCF RESTful service using DataManager and the same can be downloaded from the following location.

 

Sample Location: OrderService.zip

 

In the above sample, we have created two Grids and a WCF RESTful service with two method “GetDataWithParam” and “GetDataWithOutParam”.  Those methods are implemented from the interface IOrder.

 

The method GetDataWithOutParam will be invoked when the URI is as defined in the UriTemplate as follow.

 

[OperationContract]

[WebGet(UriTemplate = "Orders",ResponseFormat = WebMessageFormat.Json)] //Call the method without parameter

string GetDataWithOutParam();

 

The method GetDataWithParam will be invoked when a request is made without parameter.

 

[OperationContract]

[WebInvoke(Method = "POST", UriTemplate = "Orders", RequestFormat = WebMessageFormat.Json,

ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)] //Call the method with parameter

string GetDataWithParam(int take,int skip);

 

 

 

To request the web service without parameter using DataManager, please refer the following code snippet. In the below code snippet , request will be made to the web service using executeQuery method.

 

 

var data1 = ej.DataManager({ url: "/Order.svc/Orders" });

        var query = new ej.Query();

        var dm = data1.executeQuery(query); //Request the webservice

        dm.done(function (e) {

            $("#Grid").ejGrid({

                dataSource: e.result

            });

        });

 

 

To request the WCF service with parameter, please refer the following code snippet. we have used the ej.Query() to add parameters and configured the DataManager using the UrlAdaptor and hence POST request will be send to the WCF RESTful Service with parameter skip and take.

 

 

var data2 = ej.DataManager({ url: "/Order.svc/Orders" });

        data2.adaptor = new ej.UrlAdaptor();

        var query1 = new ej.Query().skip(5).take(30); //Adding parameter to be send to the webservice

        var dm1 = data2.executeQuery(query1) //Request the webservice

 

        dm1.done(function(e){

            $("#Grid1").ejGrid({

                dataSource: e.result

            });

        });

Now the request will made to the webservice with parameter value skip as 5 and take as 30.

 

 

For getting started with WCF OData service please refer the following link.

 

 http://msdn.microsoft.com/en-us/data/odata.aspx

 

Please let us know if you have any queries.

 

Regards,

Madhu Sudhanan. P


Loader.
Up arrow icon