C# 从ajax调用传递给wcf的参数接收为null

C# 从ajax调用传递给wcf的参数接收为null,c#,jquery,ajax,wcf,C#,Jquery,Ajax,Wcf,有人能帮帮我吗。从ajax传递到wcf的参数接收为null。我查看了大量的post in堆栈溢出,但找不到修复方法。下面是我的代码片段。谢谢你的期待 $.ajax({ type: "POST", url: "/CustomServices/NewsService/getmyWork", contentType: "application/json; charset=utf-8", dataType: "json", data: JSON.stringify

有人能帮帮我吗。从ajax传递到wcf的参数接收为null。我查看了大量的post in堆栈溢出,但找不到修复方法。下面是我的代码片段。谢谢你的期待

$.ajax({
    type: "POST",
    url: "/CustomServices/NewsService/getmyWork",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: JSON.stringify({ itemType: "category" }),
    processData: true,
    success: function (result) { alert("success " + result); },
    error: function (error) { alert("failure " + error.statusText); }
});
界面是

    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "getmyWork/?itemType={itemType}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
    SolutionV1.CustomServices.NewsService.DynamicItemsContext DoWork(string itemType);
};
服务方式

    public DynamicItemsContext DoWork(string itemType)
    {
        var items = RetrieveItems(itemType);
        var context = new DynamicItemsContext();
        context.Items = items.ToList();
        context.TotalCount = items.Count();
        return context;
    }

您的WCF方法设置为http post方法,但您的uri模板建议该参数将作为URL上的查询字符串参数传递

当您发出POST请求时,您的数据将在请求正文中传递,而不是在URL中传递


尝试为您的方法更改URI模板以除去查询字符串

您在url中将itemType声明为查询参数,但将其作为帖子的正文内容传递。