Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax call to WCF return "The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation .."

Tags:

json

c#

ajax

wcf

Using .NET framework 3.5. I can't figure what's happening? My Get WCF services seem to be fine using the same approach. Not sure, what's 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 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");
                }
            });

My error:

{"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.
like image 618
Chaka Avatar asked Mar 19 '23 19:03

Chaka


1 Answers

Just figured it out, needed to use "JSON.stringify"

Example:

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

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

like image 102
Chaka Avatar answered Mar 23 '23 00:03

Chaka