微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐