Kendo ui 带ASMX服务的剑道UI网格:返回XML而不是JSON

Kendo ui 带ASMX服务的剑道UI网格:返回XML而不是JSON,kendo-ui,asmx,Kendo Ui,Asmx,我正在使用下面的剑道UI网格来使用下面的ASMX服务。我已经确认,如果我使用标准JQuery ajax方法,那么该服务将使用JSON,但是如果我尝试使用kendo网格,那么我会得到以下响应: <?xml version="1.0" encoding="utf-8"?> <ArrayOfEmployeeCountByTypeModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://w

我正在使用下面的剑道UI网格来使用下面的ASMX服务。我已经确认,如果我使用标准JQuery ajax方法,那么该服务将使用JSON,但是如果我尝试使用kendo网格,那么我会得到以下响应:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfEmployeeCountByTypeModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:nil="true" xmlns="http://tempuri.org/" />


$("#grid").kendoGrid({
        dataSource: {
            type: "json",
            transport: {
                read: {
                    type: "POST",
                    dataType: "json",
                    url: "HRDashboardService.asmx/GetEmployeeCountByType",
                },
                contentType: "application/json; charset=utf-8"
            },
            schema: {
                data: "d",
                model: {
                    fields: {
                        FY: { type: "string" },
                        Month: { type: "string" },
                        AreaName: { type: "string" },
                        PFCName: { type: "string" },
                        OnRoll: { type: "number" }
                    }
                }
            }
        },
        groupable: false,
        sortable: true,
        pageable: {
            refresh: true,
            pageSizes: true
        },
        columns: [{
            field: "FY",
            width: 20,
            title: "FY"
        },
        {
            field: "Month",
            width: 20,
            title: "Month"
        },
        {
            width: 20,
            field: "AreaName",
            title: "Area Name"
        },
        {
            width: 20,
            field: "PFCName",
            title: "PFC Name"
        },
        {
            field: "EmployeeType",
            width: 40,
            title: "Employee Type"
        },
        {
            width: 20,
            field: "OnRolls",
            title: "OnRolls"
        }]
    });
以下是我的ASMX服务:

<WebMethod()> _
Public Function GetEmployeeCountByType() As List(Of EmployeeCountByTypeModel)
    Dim results As List(Of EmployeeCountByTypeModel) = Nothing

    Try
        results = (From r In DbContext.SprocEmployeeCountByType
                       Select New EmployeeCountByTypeModel With { _
                            .AreaCode = r.AreaCode, _
                            .FY = r.FY, _
                            .AreaName = r.AreaName, _
                            .EmployeeType = r.EmployeeType, _
                            .Month = r.Month, _
                            .OnRoll = r.OnRoll, _
                            .PFCCode = r.PFCCode, _
                            .PFCName = r.PFCName _
                        }).ToList()
    Catch ex As Exception

    End Try
    Return results
End Function

使用googledevelopers工具的network选项卡确保kendogriddatasource确实以POST类型发送请求,而不是GET

此链接描述了为什么asmx服务可能返回xml而不是json。。。

我也一直在努力解决这个问题,无法得到答案。 这是我发现的。 如果你仍然有问题,那就是

必须在webservice中取消注释以下代码行:

<System.Web.Script.Services.ScriptService()> _
以及Web服务的代码:

<WebMethod(), ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function getUsers() As UsersResult
    'data will be the list of objects that you want to return
    Return New UsersResult(data, data.Count)
End Function

是的,我已经确认它正在使用POST而不是GET。
Public Class UsersResult
    Private _Data As List(Of clsUsers_Item)
    Private _Total As Integer

    Public Sub New()
        _Data = Nothing
        _Total = 0
    End Sub

    Public Sub New(data As List(Of clsUsers_Item), total As Integer)
        _Data = data
        _Total = total
    End Sub

    Public Property Total() As Integer
        Get
            Return _Total
        End Get
        Set(ByVal value As Integer)
            _Total = value
        End Set
    End Property


    Public Property Data() As List(Of clsUsers_Item)
        Get
            Return _Data
        End Get
        Set(ByVal value As List(Of clsUsers_Item))
            _Data = value
        End Set
    End Property
End Class
<WebMethod(), ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function getUsers() As UsersResult
    'data will be the list of objects that you want to return
    Return New UsersResult(data, data.Count)
End Function