Ajax call to return WCF "Incoming message has unexpected message format" Raw. Expected message formats for operation .. "

Using the .NET framework 3.5. I can not understand what is happening? My Get WCF services look great using the same approach. Not sure what is missing?

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 call my web form:

 $.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");
                }
            });

My mistake:

{"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.
+4
source share
2 answers

Just thought I needed to use "JSON.stringify"

Example:

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

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

+4
source

Set content type for application / json

  $.ajax({
            url: "Services/IVOOARInventoryService.svc/PutInventory",
            type: 'POST',
            cache: false,
            dataType: 'json',
            contentType:"application/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");
            }
        });
+3
source

Source: https://habr.com/ru/post/1537883/


All Articles