c# – 对WCF的Ajax调用返回“传入消息具有意外的消息格式’Raw’.操作的预期消息格式..“

使用.NET framework 3.5.
我无法想象发生了什么?使用相同的方法,我的Get WCF服务似乎很好.
不确定,缺少什么?

WCF:

[OperationContract]
        [WebInvoke(Method = "POST",
         ResponseFormat = Webmessageformat.Json,
         BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        public void PutInventory(int caseId, DateTime dateReceived, string tamisCaseNo, string oarNo, string tin, string taxPdr, int oarTypeCd, string idrsOrgAssigned, string idrsTeAssigned, DateTime dateRequestComp, int tasCriteriaCd, string tasExpidateCd, DateTime dateEntered, string remarks)
        {
            InventoryDAL.PutInventory(caseId, dateReceived, tamisCaseNo, oarNo, tin, taxPdr, oarTypeCd, idrsOrgAssigned, idrsTeAssigned, dateRequestComp, tasCriteriaCd, tasExpidateCd, dateEntered, remarks);
        }

Ajax调用我的webform:

 $.ajax({
                url: "Services/IVOOARInventoryService.svc/PutInventory",
                type: 'POST',
                cache: false,
                dataType: 'json',
                data: ({
                    caseId: '<%=Request.QueryString["id"]%>', dateReceived: $("#dateEntered").val(), tamisCaseNo: $("#tamisCaseNo").val(), oarNo:  $("#OARNo").val(), tin:$("#tin").val(), taxPdr: $("#taxPeriod").val(), oarTypeCd: $("#oarType").val(), idrsOrgAssigned: $("#idrsOrgAssigned").val(), idrsTeAssigned: $("#idrsTeAssigned").val(), dateRequestComp: $("#dateRequestComp").val(), tasCriteriaCd: $("#tasCriteriaComp").val(), tasExpidateCd:$("#tasExpediateCd").val(), dateEntered: $("#dateEntered").val(), remarks: $("#remarks").val()
                }),
                error: function (jqXHR, textStatus, errorThrown) {
                    $("div#spinner").fadeOut("slow");
                    alert(errorThrown);
                },
                success: function (json) {
                    $("div#spinner").fadeOut("slow");
                }
            });

我的错误

{"ExceptionDetail":{"HelpLink":null,"InnerException":null,"Message":"The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.

解决方法:

刚想通了,需要使用“JSON.stringify”

例:

 data: JSON.stringify({
                    caseId: "18"
                    ...etc..
                }),

http://encosia.com/asmx-scriptservice-mistake-invalid-json-primitive/

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...