C# 传入消息具有意外的消息格式';原始的';。操作的预期消息格式为';Xml'';Json';
我正在尝试对wcf服务进行跨域jQueryAjax调用。我尝试了一个不带参数并返回数据的服务。它很好用。但当我尝试使用参数调用wcf服务时,它会导致以下错误:C# 传入消息具有意外的消息格式';原始的';。操作的预期消息格式为';Xml'';Json';,c#,jquery,ajax,wcf,C#,Jquery,Ajax,Wcf,我正在尝试对wcf服务进行跨域jQueryAjax调用。我尝试了一个不带参数并返回数据的服务。它很好用。但当我尝试使用参数调用wcf服务时,它会导致以下错误: The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json' 以下是服务代码: public string GetData(int value)
The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'
以下是服务代码:
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
这是运营合同:
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string GetData(int value);
下面是jQuery AJAX调用:
$.ajax({
url: 'http://10.1.2.167:99/Service1.svc/GetData',
data: JSON.stringify({ "value": 1 }),
type: 'POST',
success: function (response) {
console.log(response);
},
error: function (error) {
console.log(error);
}
});
任何人都可以指出可能的错误….尝试将contentType:“application/json;charset=utf-8”,数据类型:“json”添加到Ajax中parameters@artm它给出以下错误
加载资源失败:服务器响应状态为405(方法不允许)
在浏览器中输入时,您是否获得wcf的定义?