如何将json数据发布到WCF Web服务? [英] How can I POST json data to a WCF web service?

查看:92
本文介绍了如何将json数据发布到WCF Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在wcf Web服务上具有以下方法.

I have the following method on a wcf web service.

   [OperationContract]
    [WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    RequestFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    public void UpdateAnalysisParameters(string parameterSets)
    {
       //....
    }

但是我在向它发布数据时遇到了麻烦.我正在使用以下jquery Ajax调用.

But I am having trouble posting data to it. I am using the following jquery Ajax call.

    $.ajax({
        url: "/ATOMWebService.svc/UpdateAnalysisParameters",
        dataType: "json",
        type: "POST",
        data: JSON.stringify({ parameterSets: "Dave" })
    });

但是Web服务正在响应传入消息具有意外消息格式'Raw'. 该操作的预期消息格式为'Xml','Json'."

But the web service is responding with "The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'."

如何将json数据发布到此Web服务?

How can I post json data to this web service?

推荐答案

尝试在ajax请求中指定内容类型:

Try specifying the content type in your ajax request:

contentType: "application/json"

设置dataType仅向jquery提示如何处理接收到的响应.

Setting the dataType only gives a hint to jquery about how to handle the received response.

这篇关于如何将json数据发布到WCF Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆