从jQuery调用时WCF服务错误

时间:2012-04-10 17:54:34

标签: jquery wcf

尝试使用下面的jquery代码调用以下服务时出现500错误,有人可以帮忙吗?

result.status = 500 result.statusText =“System.ServiceModel.ServiceActivationException”

这是SVC服务:

    [WebInvoke( Method = "POST", 
                UriTemplate = "/tools/data/SearchAll")]
    public JsonArray SearchAll(string tool, JsonObject filters)
    {...}

这是jQuery服务调用:

    //Generic function to call WCF  Service
    function callService() {
        $.ajax({
            type: type, //GET or POST or PUT or DELETE verb
            url: url, // Location of the service
            data: data, //Data sent to server
            contentType: contentType, // content type sent to server
            dataType: dataType, //Expected data format from server
            processdata: processData, //True or False
            success: function (msg) {//On Successfull service call
                serviceSucceeded(msg);
            },
            error: serviceFailed// When Service call fails
        });
    }



    function searchAll() {
        var tool = "1";
        var filters = '{{ "col": "thiscol", "val": "thisval" }, { "col": "thiscol2", "val": "thisval2" }, { "col": "thiscol3", "val": "thisval3"}}';
        type = "POST";
        url = "ToolService.svc/tools/data/SearchAll";
        contentType = "application/json; charset=utf-8";
        dataType = "json";
        data = '{ "tool": "' + tool + '", "filters" : "' + filters + '" }',
        processData = false;
        method = "SearchAll";
        callService();
    }

1 个答案:

答案 0 :(得分:1)

我对此进行了排序,事实证明(除其他事项外)将json传递给服务方法,现在所有的外观都很好。

感谢您的帮助。