Connect to a JSON Web Service

3 posts, 0 answers
  1. Filip
    Filip avatar
    35 posts
    Member since:
    Jul 2013

    Posted 17 Jul 2013 Link to this post

    Hello, 
    I am trying to connect to ASMX Web Service that returns JSON. Service receives strUser and strPassword as a parameter, and returns array of SomeEvents. SomeEvent has two fields: eventID and eventName.
     I am getting internal server error, and I believe it has something to do with the format of the data I'm sending/receiving. I would be grateful if you take a look and tell me how to solve this:

    var eventsModel = (function () {
           var eventModel = {
                id: 'eventID',
                fields: {
                    Text: {
                        field: 'eventName',
                        defaultValue: ''
                    }
                 }
            };
            var eventsDataSource = new kendo.data.DataSource({
                schema: {
                    model: eventModel
                },
                transport: {
                    read: {
                      url: ASMX + "GetOrganizerEventsJSON",
                      type: "POST",
                      data: { strUser: "someUsername", strPasswort: "somePassword" },
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                    }
                }
            });
            return {
                events: eventsDataSource,
            };
    }());

    Web method looks like this:
    <WebMethod()> _
        <ScriptMethod(ResponseFormat:=ResponseFormat.JSON)> _
        Public Function getOrganizerEventsJSON(ByVal strUser As String, ByVal strPasswort As String) As SomeEvent()
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 25 Jul 2013 Link to this post

    Hi Filip,

    Syntactically speaking everything seems correct, but we're missing some key part as what is ASMX. It should be the uri to the service e.g. http://mydomain.com/myservice.svc/. If the service is on another domain, be sure to specify jsonp instead of json for cross-domain access.

    In general, your inquiry is not directly related to Icenium (nor Kendo), so you might consider posting this question on generic forums such as stackoverflow in order to receive feedback from other expert developers.

    Regards,
    Steve
    Telerik

    Do you enjoy Icenium? Vote for it as your favorite new product here (use short code H048S).
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  3. Kendo UI is VS 2017 Ready
  4. Suma
    Suma avatar
    49 posts
    Member since:
    Apr 2012

    Posted 30 Jul 2013 Link to this post

    hi here is the code for bind list by using wcf service


    <div data-role="view" id="vwCustomersList" data-title="Customers" data-init="GetAllCustomerList"  >
    <div class="maincontaner" >

    <div class="header-strip" >
    <div style="float:left; padding-left:10px; text-align:left; color:white; font-size:14px; font-family:arial; font-weight:bold;" >Customers</div>

    <div style="float:right; padding-right:10px;">
    <a data-align="right" href="#tabstrip-openwo" data-role="button" class="back-btn" id="btnBackCustomers"   >Back</a>
    </div>

    </div>

    <div class="header-strip-1 list-items-add" >
                         <div class="cr-div-col-h1-add">Customer ID</div>
    <div class="cr-div-col-h2-add">Name</div>
                        <div class="cr-div-col-h1-add">Phone No</div>
                        
    </div>
    <ul  id="lstCustomer"  data-role="listview" auto-bind="false" style="text-align:left;" ></ul>

    </div>

    </div>
    <script id="lstCustomer-template" type="text/x-kendo-template">

    <div class="list-items-add">
                    <div class="cr-div-col-add1">#= checkNullOrEmpty(_customerID) #</div>
    <div class="cr-div-col-add2">#= checkNullOrEmpty(_businessName) #</div>
                    <div class="cr-div-col-add1">#= checkNullOrEmpty(_phone) #</div>
    </div>
    </script>




    var ServiceURL="http://183.169.1.672/your url";
    function GetAllCustomerList(e) {

        app.showLoading();
    $.ajax({
    type: 'GET',
    contentType: "application/json; charset=utf-8",
    url: ServiceURL + "/GetAllCustomerList",
             data: {EMail:userData._eMail,Password:userData._password,LoginDateTime: userData._loginDateTimeString}, //Data sent to server
    dataType: "jsonp",
    success: function (data, textStatus) {
    if (textStatus == "success") { 
                         customerList= data;  
    $("#lstCustomer").kendoMobileListView({
    dataSource: data,
    endlessScroll: true,
    template: $("#lstCustomer-template").text(),
    scrollTreshold: 30,
                            
    click: function(e) {
    customerData = e.dataItem;
                            workordercreatemode=1;
                          AddWorkOrder(null);
                           app.navigate("#vwEditWorkOrderbyTechnician");
                        
    }
    });
    app.hideLoading();
    }
    },
    error: function (data, textStatus) {
    alert('An error has occured!');
    }
    }); 
    }

Back to Top