本文介绍了从IE 8调用restful wcf post方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好我的wcf代码如下: 接口: [OperationContract] [WebInvoke(Method = POST,BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = / SaveURLTable)] Int64 SaveURLTable( string URL, string UniqueID); 方法: public Int64 SaveURLTable( String URL,字符串 UniqueID) { // 我的代码在这里返回价值 } 现在我可以通过m调用它来自IE10,FF,Chrome的httprequest电话,就像现代网络浏览器一样,但是当我从IE8调用它时,它会给我以下错误: < p > 服务器遇到处理请求的错误。异常消息是'传入消息具有意外的消息格式'Raw'。操作的预期消息格式是'Xml','Json'。这可能是因为尚未在绑定上配置WebContentTypeMapper。有关更多详细信息,请参阅WebContentTypeMapper的文档。请参阅服务器日志以获取更多详异常堆栈跟踪是:< / p > < p > ; at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message,Object [] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message,Object [] parameters) System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& amp; rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& amp; rpc) at System.ServiceModel.Dispatcher。 System.ServiceModel的System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& amp; rpc)的ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& amp; rpc)。 Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)< / p > 在提琴手中找到。 现代浏览器的json代码如下: $。ajax({类型: POST, crossDomain:true, url:query, data:'{URL:'+ dbString +',UniqueID:}', contentType:application / json; charset = utf-8, dataType:XML, processdata:true, success:function(data1){ if(data1!= null){ var data = data1; alert(data); } },错误:function(response,textStatus,errorThrown){ alert(响应。 responseText); } }); 和我的IE8 XDR代码如下: var postdata = ' {URL:' + dbString + ' ,UniqueID:}'; if (window.XDomainRequest){ var xdr = 新 XDomai nRequest(); if (xdr){ xdr.onload = function(){ data = xdr.responseText; alert(data); } xdr.onerror = function(){ / * 此处的错误处理* / } xdr.open(' POST',query); xdr.send(JSON.stringify(postdata)); } } 我的httprequest代码工作正常但是XDR代码没有工作,并给我上面的错误。请帮我解决这个问题... 我想用IE8的数据发帖请求,请帮帮我。解决方案 .ajax({类型:POST, crossDomain:true, url:query, data:'{URL: '+ dbString +',UniqueID:}', contentType:application / json; charset = utf-8, dataType:XML, processdata :true,成功:function(data1){ if(data1!= null){ var data = data1; alert(data); } },错误:function(response,textStatus,errorThrown){ alert(response.responseText); } }); 和我的IE8 XDR代码如下: var postdata = ' {URL:' + dbString + ' ,UniqueID:}' ; if (window.XDomainRequest){ var xdr = new XDomainRequest(); if (xdr){ xdr.onload = function(){ data = xdr.responseText; alert(data); } xdr.onerror = function(){ / * 此处的错误处理* / } xdr.open(' POST',query); xdr.send(JSON.stringify(postdata)); } } 我的httprequest代码工作正常但是XDR代码没有工作,并给我上面的错误。请帮我解决这个问题...... 我想用IE8的数据发帖请求,请帮帮我。 您的 OperationContract 无效。尝试更改它并重新运行。 [OperationContract] [WebInvoke(Method = POST,BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormate.Json, UriTemplate = / SaveURLTable)] Int64 SaveURLTable(字符串 URL,字符串 UniqueID); 此外!如果您要以JSON格式发送数据,则只在参数中指定自定义对象。 编辑:更改 UriTemplate 像这样: / SaveURLTable?URL = {URL}& UniqueID = {UniqueID} 您已设置 contentType: application / json; charset = utf-8 但同样,你没有发送任何JSON。删除此Content-Type,然后重试。 Hello my wcf code is below:Interface:[OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/SaveURLTable")] Int64 SaveURLTable(string URL, string UniqueID);Method:public Int64 SaveURLTable(String URL, String UniqueID){ // my code here with return value}now i m able to call this by making httprequest call from IE10, FF, Chrome like modern web browser but when i call this from IE8 then its giving me following error:<p>The server encountered an error processing the request. The exception message is '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.'. See server logs for more details. The exception stack trace is: </p> <p> at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</p>Found in fiddler.my json code for modern browser is below:$.ajax({ type: "POST", crossDomain: true, url: query, data: '{"URL": "' + dbString + '","UniqueID": ""}', contentType: "application/json; charset=utf-8", dataType: "XML", processdata: true, success: function (data1) { if (data1 != null) { var data = data1;alert(data); } }, error: function (response, textStatus, errorThrown) { alert(response.responseText); } });and my IE8 XDR code is below:var postdata = '{"URL": "' + dbString + '","UniqueID": ""}'; if (window.XDomainRequest) { var xdr = new XDomainRequest(); if (xdr) { xdr.onload = function () { data = xdr.responseText; alert(data); } xdr.onerror = function () { /* error handling here */ } xdr.open('POST', query); xdr.send(JSON.stringify(postdata)); } }My httprequest code is working correct but XDR code is not working and giving me above error. please help me to solve this guys...I want to make post request with data from IE8, please help me. 解决方案 .ajax({ type: "POST", crossDomain: true, url: query, data: '{"URL": "' + dbString + '","UniqueID": ""}', contentType: "application/json; charset=utf-8", dataType: "XML", processdata: true, success: function (data1) { if (data1 != null) { var data = data1;alert(data); } }, error: function (response, textStatus, errorThrown) { alert(response.responseText); } });and my IE8 XDR code is below:var postdata = '{"URL": "' + dbString + '","UniqueID": ""}'; if (window.XDomainRequest) { var xdr = new XDomainRequest(); if (xdr) { xdr.onload = function () { data = xdr.responseText; alert(data); } xdr.onerror = function () { /* error handling here */ } xdr.open('POST', query); xdr.send(JSON.stringify(postdata)); } }My httprequest code is working correct but XDR code is not working and giving me above error. please help me to solve this guys...I want to make post request with data from IE8, please help me.Your OperationContract is not valid. Try changing it and re run.[OperationContract][WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,RequestFormat = WebMessageFormate.Json,UriTemplate = "/SaveURLTable")]Int64 SaveURLTable(string URL, string UniqueID);Moreover! If you are sending data in JSON format, then only specify your custom object in parameter.EDIT: Change your UriTemplate like this:/SaveURLTable?URL={URL}&UniqueID={UniqueID}You have set contentType: "application/json; charset=utf-8" but again, you are not sending any JSON. Remove this Content-Type and then try again. 这篇关于从IE 8调用restful wcf post方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-19 22:32