Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
540
Please let me know on how to bind the data from wcf service
posted

I need to bind the datasource for JQuery grid from WCF service. The WCF service returns list. The WCF service is as follows. 

I am receiving the below error:

Microsoft JScript runtime error: The remote request to fetch data has failed:  (parsererror) There was an error parsing the JSON data and applying the defined data schema: 'length' is null or not an object

Please let me know on how to bind the data from wcf service. 

 

Below is the code for WCF service

 

namespace InfraApplication

{

    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "SampleService" in code, svc and config file together.

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    public class SampleService : ISampleService

    {

        public void DoWork()

        {

        }

 

        public List<CustomerViewModel> GetSortedCustomers()

        {

            List<CustomerViewModel> cvml = new List<CustomerViewModel>();

            CustomerViewModel cvm = new CustomerViewModel();

            cvm.CompanyName = "ABC Company";

            cvm.ContactName = "Krishna";

            cvml.Add(cvm);

            return cvml;

        }

    }

 

    public class CustomerViewModel

    {

        public string ContactName { get; set; }

        public string CompanyName { get; set; }

    }

}

The WCF service uses webHttpBinding. 
In the client side the code is as below
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="InfraApplication.index" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.min.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui.js" type="text/javascript"></script>      
    <script src="Scripts/jquery.tmpl.js" type="text/javascript"></script>
    <script src="Infragistics/js/infragistics.loader.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        $.ig.loader({
            scriptPath: "/Infragistics/js/",
            cssPath: "/Infragistics/css/",
            resources: "igGrid.*"
        });
        $.ig.loader(function () {
            $("#grid1").igGrid({
                height: 500,
                columns: [
   { headerText: "Company Name", key: "CompanyName", dataType: "string" },
   { headerText: "Contact Name", key: "ContactName", dataType: "string" },    
   ],
                autoGenerateColumns: false,
                dataSource: "/SampleService.svc/GetSortedCustomers",
                responseDataKey: "d",
                features: [
   {
       name: "Paging",
       type: "local",
       pageSize: 10
   },
                    {
                        name: "Filtering",
                        allowFiltering: true,
                        type: "local"
                    }
                ]
            });
        });          
    </script>
    
</head>
<body>    
    <table id="grid1"></table>    
</body>
</html>