Providing data from C#

5 posts, 0 answers
  1. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 18 Feb 2012 Link to this post

    Hi,

    With the uncertainty over sliverlight, I am focusing on html 5. However, html 5 does not seem to be able to fill the void of a server-side tech like silverlight (or so I think!).

    Specifcally, with kendo UI, can I stream data to charts in a real time fashion with C#? I think I saw a thread about providing data from C# to Kendo UI?

    Also, I would love to see the product be = to Kendo UI in terms of features and controls (E.g. the book control).



    Thanks
  2. Gabriel
    Gabriel avatar
    79 posts
    Member since:
    Nov 2011

    Posted 18 Feb 2012 Link to this post

    You can use an ASP.NET web service written in C# or use the new Web API. I use the latter (with VB) with no problems at all.
  3. G S S
    G S S avatar
    85 posts
    Member since:
    Mar 2008

    Posted 20 Feb 2012 Link to this post

    Thanks. Is there any example of this? I realise you're not a Telerik employee.
  4. Gabriel
    Gabriel avatar
    79 posts
    Member since:
    Nov 2011

    Posted 20 Feb 2012 Link to this post

    This is the JavaScript I have for Autocomplete:
    $("#txtSearch").kendoAutoComplete({
            change: onSearchClick,
            minLength: 3,
            dataTextField: "title",
            dataSource: new kendo.data.DataSource({
                type: "json",
                pageSize: 8,
                serverFiltering: true, // Required to prevent caching.
                serverPaging: true, // Required to prevent caching. 
                transport: {
                    read: getRootDomain() + "/autoComplete",
                    parameterMap: function (options) {
                        return $.extend(options, {
                            title: $("#txtSearch").data("kendoAutoComplete").value()
                        });
                    }
                },
                error: function (e) {
                    // do something
                }
            })
        });


    This is the code for the service.
    Imports System.Json
    Imports System.ServiceModel
    Imports System.ServiceModel.Web
    Imports WebMatrix.Data
     
    <ServiceContract()>
    Public Class Autocomplete
     
    #Region "Public methods"
     
        <WebGet(UriTemplate:="")>
        Public Function [Get]() As JsonArray
     
            ' Vars.
            Dim context = System.Web.HttpContext.Current
            Dim query As String
            Dim db = Database.Open("ILTV")
     
            ' Find the top 10 matches for the partial title typed.
            query = "SELECT TOP 10 Title, SKU, Collection FROM Titles WHERE Title LIKE '%" & context.Request("title") & "%' ORDER BY Title ASC"
            Dim result = db.Query(query)
     
            ' Format results for the JSON parser.
            Dim results As New List(Of Suggestion)
            For Each r In result
                Dim s As New Suggestion With {.title = r.Title, .url = r.Collection & "/" & Utilities.GetFriendlyProductUrl(r.Title) & "/" & r.SKU.ToString.ToLower}
                results.Add(s)
            Next
     
            ' Encode the JSON array.
            Dim jString As String = System.Web.Helpers.Json.Encode(results)
            Return JsonArray.Parse(jString)
     
        End Function
     
    #End Region
     
        ' todo: comment me!
        ' lowercase on purpose to make it niceer when parsed to JSON.
    #Region "Data models"
     
        Public Class Suggestion
     
            Public Property title As String
            Public Property url As String
     
        End Class
     
    #End Region
        
    End Class


    You will need to download the new Web API preview from wcf.codeplex.com from Microsoft. It is just a few references you need to add + a smidge of code to register the service. It is pretty straight-forward enough + there is loads of sample with the Web API. You can also not use WCF by just have a webpage that returns the data if you are using Web Pages Razor.
  5. 1zias01
    1zias01 avatar
    12 posts
    Member since:
    Sep 2012

    Posted 20 Feb 2012 Link to this post

    Here is an example I did using the AutoComplete control.

    $(document).ready(function () {
     
        $("#SearchBox").kendoAutoComplete({
            minLength2,
            dataTextField"VenueName",
            template$('#tmplSearchResults').html(),
            dataSource: {
                type"json",
                severFilteringtrue,
                serverPagingtrue,
                transport: {
                    read"Services/Businesses.asmx/GetBusinessVenueAddressContact",
                    parameterMapfunction () {
                        return { venueName$('#SearchBox').val(), reviewStatusId'1' };
                    }
                }
            }
        });
    
    
    
    
    
    
    });

    at the top of your Web Service (.asmx)  make sure you uncomment this line
    [System.Web.Script.Services.ScriptService]
    

    In my javascript code above, this is the path to your web service and the name of the Web Method that you are calling.  
    Services/Businesses.asmx/GetBusinessVenueAddressContact

    I've been using jQuery and services like this (including WCF Web API) for over a year now, creating RIAs similar to what you might create with Silverlight.  But I feel that this way is better and Silverlight is on the way out (if it ever got off the ground to begin with).


    Hope that helps.
Back to Top