Jquery AJAX 到 asmx web 方法得到错误作为响应

Jquery AJAX to asmx web method get error as response

好的,我就是这样做的:

客户:

function AjaxCall(url, method, data, OnSuccessFunction, OnErrorFunction) {
    var ajaxData = data;
    ajaxData = JSON.stringify(ajaxData);
    var ajaxURL = url + "/" + method;
    $.ajax({
        type: "POST",
        url: ajaxURL,
        data: ajaxData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function () {
            OnSuccessFunction.apply(this, arguments);
        },
        error: function () {
            $('.ProgressBar').hide();
            OnErrorFunction.apply(this, arguments);
        }
    });
}

$(document).ready(function () {

   AjaxCall("http://localhost:34714/WebService1.asmx", "GetChart", { filename: 'excel-demo.xlsx', sheet: 'chart_param' }, GetTradingViewSuccess, GetTradingViewError)

});

var GetTradingViewSuccess = function (data) {

}

var GetTradingViewError = function (jqXHR, textStatus, errorThrown) {

}

asmx:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using WebApplication2.Classes;

namespace WebApplication3
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
         [System.Web.Script.Services.ScriptMethod()]
        [WebMethod]
        public string add()
        {
            return "sd";
        }

        [WebMethod(EnableSession = true)]
         public Chart GetChart(string filename, string sheet)
        {
           Chart c = new Chart();
           //do something

            return c;
        }
    }
}

网络配置:

<?xml version="1.0"?>

<configuration>
    <system.web>
      <webServices>
        <protocols>
          <add name="HttpGet"/>
          <add name="HttpPost"/>
        </protocols>
      </webServices>

      <compilation debug="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1" />
    </system.web>

</configuration>

我每次都收到错误消息:

POST http://localhost:34714/WebService1.asmx/GetChart 500 (Internal Server Error)send @ jquery-1.7.2.min.js:4f.extend.ajax @ jquery-1.7.2.min.js:4AjaxCall @ Common.js:5(anonymous function) @ chart.html:15o @ jquery-1.7.2.min.js:2p.fireWith @ jquery-1.7.2.min.js:2e.extend.ready @ jquery-1.7.2.min.js:2c.addEventListener.B @ jquery-1.7.2.min.js:2 errorThrown "Internal Server Error"

我在 asmx 文件 - GetChart webmethod 中放置了断点,但从未达到它。 我做错了什么?

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

取消注释下面的行。

// [System.Web.Script.Services.ScriptService]

变成

[System.Web.Script.Services.ScriptService]