使用.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/