This is a migrated thread and some comments may be shown as answers.

Binding to remote database with asp.net web service

2 Answers 177 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Francois
Top achievements
Rank 1
Francois asked on 13 Mar 2012, 02:59 PM
Hi,

I'm having some trouble binding a KendoUI chart to a remote database through a web service.

Here is my code:

$("#chart").kendoChart({
    theme: $(document).data("kendoSkin") || "default",
    dataSource: {
        transport: {
            read: {
                url: "/WebServices/WebFunctions.asmx/RetrieveProjectCountByBMP",
                dataType: "json"
            }
        },
        schema: {
            model: {
                fields: {
                    Code: { type: "string" },
                    Count: { type: "number" }
                }
            }
        },
        sort: {
            field: "Code",
            dir: "asc"
        }
    },
    title: {
        text: "Project Count by BMP"
    },
    seriesDefaults: {
        type: "column"
    },
    series: [{
        field: "Count",
        name: "Project Count"
    }],
    categoryAxis: {
        field: "Code"
    },
    tooltip: {
        visible: true,
        format: "{0:N0}"
    }
});

and here is the web service code:

<WebMethod(EnableSession:=True)> _
Public Function RetrieveProjectCountByBMP() As Object
    Dim returnData = (From p As Project In Project.RetrieveAll() _
                     Join cs As ClaimScope In ClaimScope.RetrieveAll() On p.ProjectId Equals cs.ProjectId _
                     Join b As BMP In BMP.RetrieveAll On cs.BMPId Equals b.BMPId _
                     Where (p.ProjectMilestoneId = 17 Or p.ProjectMilestoneId = 18 Or p.ProjectMilestoneId = 19) _
                     And p.FiscalyearId = 5 _
                     Select b.Code, p.ProjectId).GroupBy( _
                        Function(bmpCode) bmpCode.Code _
                        , Function(proj) proj.ProjectId _
                        , Function(bmpCode, projects) New With {.Code = bmpCode, .Count = projects.Count()})
 
    Dim serializedReturnData As JavaScriptSerializer = New JavaScriptSerializer(returnData)
 
    Return serializedReturnData.Serialize(serializedReturnData)
 
    Return serializedReturnData
End Function


I've verified that my webservice returns a complete dataset. 
The problem is that when I run the code, the chart doesn't get populated. There are no error messages and no events fired in the event log.

The only issue I can find is that the webservice returns the data with leading a trailing quotes, like this:

"[{"Code":"1301","Count":239},{"Code":"1401","Count":178},{"Code":"1001","Count":33}]"

When I copy the data returned from the web service into a .json file and bind the chart to that, it works fine. However, I have to remove the leading and trailing quotes to get it to work.

How can I get my webservice to return my data in proper JSON format?

Thanks. 

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 15 Mar 2012, 04:12 PM
Hello Francois,

I believe the problem is caused by the fact that your function is returning string ( serializedReturnData ) which is being serialized one again by the WebMethod. The solution would be to return an object ( returnData ) and let the web method to handle the serialization.

I hope this information helps.

Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Monique
Top achievements
Rank 1
answered on 30 Mar 2012, 03:31 PM
Hello Francois


Did you solved your problem with  asp. net WebService?

I am having the same situation

I was hoping you could help me, please.

Have a nice day
M.
Tags
Data Source
Asked by
Francois
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Monique
Top achievements
Rank 1
Share this question
or