Passing Parameters to a WCF WebGet Method

2 posts, 0 answers
  1. Alan
    Alan avatar
    5 posts
    Member since:
    Apr 2012

    Posted 06 Jul 2012 Link to this post

    I have created a WCF Data Service that (amongst other things) contains a WebGet Method which accepts a string parameter.  How do I send this parameter from kendoUI Mobile?

    WebMethod:

    [WebGet]
    public IEnumerable<T> GetData(string str)
    {
        var linqQuery = from x in Products
                                 where productName == str
                                 select x;
        return linqQuery;
    }

    I am trying to call the webmethod as follows:

    function GetProduct(name) {
        $("#product-listview").kendoMobileListView({
            dataSource: {
                transport: {
                    read: {
                        contentType: "application/json; charset=utf-8",
                        url: "http://ProductDataService.svc/GetData",
                        dataType: "json",
                        data: {param: name }
                   }
                },
                schema: {
                    data: "d"
                },
                parameterMap: function (options) {
                    kendo.ui.progress($("#product-listview"), false);
                    return kendo.stringify(options);
                }
            },
            template: $("#product_template").text()
        });
    }

    This returns no data, and no error. Can anyone help?
  2. Joshua
    Joshua avatar
    69 posts
    Member since:
    May 2012

    Posted 17 Aug 2012 Link to this post

    I am having some trouble when using WebGet. 

    If I use operationcontract and do a post i can do the following:
    var clinicDS = new kendo.data.DataSource({
        transport: {
            read: {
                url: $.radoloCommon.resolveUrl("~/Services/GetHealthy.svc/ClinicSearchByName"),
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "json"
            },
            parameterMap: function (options) {
                return kendo.stringify( { NameFilter: $('#clinicSearch').val(),IncludeDisabled:false, Options: options });
            }
        },
        schema: {
            data: "d.Data",
            model: { id: "ID" },
            total: "d.Total"
        },
        pageSize: 10,
        serverPaging: true
    });


    with the matching wcf info:
    public IEnumerable<Model.ClinicInfo> ClinicSearchByName(string NameFilter, bool IncludeDisabled, Radolo.Common.Model.DataSourceServerOptions Options)
     
        public class DataSourceServerOptions
        {
            public int take { get; set; }
            public int skip { get; set; }
            public int page { get; set; }
            public int pageSize { get; set; }
            public object[] group { get; set; }
            public KendoSort[] sort { get; set; }
        }
     
        public class KendoSort
        {
            public string field { get; set; }
            public string dir { get; set; }
        }
Back to Top