I have tried every combination to send a request to send a POST request to RESTful WCF from jQuery.

我已经尝试了每个组合来发送请求从jQuery向RESTful WCF发送POST请求。

Can someone imitate and make it working. Code is here : http://pastebin.com/Ua97919C

有人可以模仿并使其发挥作用。代码在这里:http://pastebin.com/Ua97919C

I am working with WCF from past 2 years, but every time i send a POST request it makes me struggle a lot.

我在过去2年与WCF合作,但每次发送POST请求都会让我很烦恼。

I am struggling to make it work from past 4 days and gone through atleast 35-40 posts.

我努力让它在过去的4天里工作,并且经历了至少35-40个帖子。

Eventually, this request would be sent from iPhone to WCF.

最终,此请求将从iPhone发送到WCF。

When i check it with Fiddler the error mostly is: *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: at

当我用Fiddler检查时,错误主要是:*服务器遇到处理请求的错误。异常消息是'传入消息具有意外的消息格式'Raw'。该操作的预期消息格式是'Xml','Json'。这可能是因为尚未在绑定上配置WebContentTypeMapper。有关更多详细信息,请参阅WebContentTypeMapper的文档。请参阅服务器日志以获取更多详异常堆栈跟踪是: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& rpc)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

2 个解决方案

#1


4

Add a Global.ascx file in youe solution and replace the code with following

在您的解决方案中添加Global.ascx文件,并使用以下代码替换代码

protected void Application_BeginRequest(object sender, EventArgs e)
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
    if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
    {
        HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
        HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
        HttpContext.Current.Response.End();
    }
}

one more thing chnage dataType:'text'

还有一件事chnage dataType:'text'

$.ajax({
    type: "POST",
    url: "http://localhost:4638/Edulink.svc/SaveUserData",                        
    dataType: "text",
    contentType: "application/json",
    data:'{"EmailID":"praveen", "LevelID": 1}',         
    success:function(data, status) {             
        console.log(data); //gives 1                
    },
    error:function(request, status, error) {
        alert("o0ops");           
    }
});

更多相关文章

  1. jquery 生成table表格 部分代码
  2. 使用jquery的$ .ajax来获取node.js脚本的输出,而不是它的代码
  3. Server.Htmlencode用于文本域显示带的html代码
  4. IOS学习之WebView加载本地HTML代码或网络资源
  5. html5 css3 背景视频循环播放代码
  6. HTML5 标签audio添加网页背景音乐代码
  7. Jquery - 表单验证,为错误消息添加css样式
  8. HTML5 windows和iframe之间传递消息
  9. 我无法理解为什么我的代码中的单击选择文本

随机推荐

  1. Android 中Edittext属性集合
  2. Android中Intent对应的category列表大全
  3. Android(安卓)Selector和Shape的用法
  4. Linearlayout与Relativelayout布局回顾 .
  5. 通过Android(安卓)Binder拓展系统服务
  6. Android API中文文档(111) —— MailTo
  7. 深入讲解WebView——下
  8. Android Activity动画属性简介
  9. js与Android和iOS的webview交互,兼容的写
  10. android:layout_marginLeft等的简单用法