C# 对WCF的Ajax调用返回错误

C# 对WCF的Ajax调用返回错误,c#,jquery,asp.net,ajax,wcf,C#,Jquery,Asp.net,Ajax,Wcf,我得到了一个错误: 异常消息为“传入消息有意外错误” 消息格式为“原始”。操作的预期消息格式 是“Xml”、“Json”。这可能是因为WebContentTypeMapper没有 已在绑定上配置。请参阅的文档 有关详细信息,请参阅WebContentTypeMapper。“。有关更多信息,请参阅服务器日志 细节 我正在对WCF服务进行ajax调用,如下所示: function WCFJSON() { var now = new Date(); var getFromDate = dateToW

我得到了一个错误:

异常消息为“传入消息有意外错误” 消息格式为“原始”。操作的预期消息格式 是“Xml”、“Json”。这可能是因为WebContentTypeMapper没有 已在绑定上配置。请参阅的文档 有关详细信息,请参阅WebContentTypeMapper。“。有关更多信息,请参阅服务器日志 细节

我正在对WCF服务进行ajax调用,如下所示:

function WCFJSON() {
var now = new Date();

var getFromDate = dateToWcf(new Date(now - (60000 * 1440)));

var userid = "1";
m_Type = "POST";
m_Url = "https://dev-04.boldgroup.int/ManitouDashboard/DashboardProxyService.svc/GetStats"
m_Data = "{'fromdate':'" + getFromDate + "'getvaluelist':'[1,2,3]'}";
m_DataType = "json";
m_ProcessData = true;             
CallService();
}

function dateToWcf(input) {
var d = new Date(input);
if (isNaN(d)) {
    throw new Error("input not date");
}
var date = '\\\/Date(' + d.getTime() + '-0000)\\\/';
return date;
}

function CallService() {
$.ajax({
    type: m_Type,           //GET or POST or PUT or DELETE verb                  
    url: m_Url,                 //Location of the service   
    data: m_Data,
    dataType: m_DataType,   //Expected data format from server                  
    processdata: m_ProcessData, //True or False
    crossdomain: true,    
    contentType: "application/json",             
    success: function (msg) {   //On Successfull service call                      
        ServiceSucceeded(msg);
    },
    error: function (jqXHR, textStatus, errorThrown) {
        ServiceFailed("jqXHT: " + jqXHR.result + "Text Status: " + textStatus + " Error Thrown: " + errorThrown );
    } // When Service call fails              
});
}
我的服务合同声明如下:

[ServiceContract]
public interface IDashboardWCFService
{
    [OperationContract]
    [WebInvoke(UriTemplate = "GetStats", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
    Dictionary<int,List<StatValue>> GetStats(DateTime getFromDate, List<int> getValueList);

    [OperationContract]
    [WebGet(UriTemplate = "GetStatTypes", ResponseFormat = WebMessageFormat.Json)]
    List<StatType> GetStatTypes();
}
[服务合同]
公共接口IDashboardWCFService
{
[经营合同]
[WebInvoke(UriTemplate=“GetStats”,ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped)]
字典GetStats(DateTime getFromDate,List getValueList);
[经营合同]
[WebGet(UriTemplate=“GetStatTypes”,ResponseFormat=WebMessageFormat.Json)]
列出GetStatTypes();
}
我在电话里做了什么不正确的事吗

  • 您的
    m_数据中似乎有错误。两项之间没有逗号
    (m_Data=“{'fromdate':'”+getFromDate+““getvaluelist':'[1,2,3]}”)
  • 匹配参数名称(
    fromdate
    ->
    getFromDate
    getvaluelist
    ->
    getvaluelist
  • 使用ISO 8601日期-时间格式(2012-08-15T00:00:00+02:00)(我总是使用日期/时间,它太棒了)
  • 删除多余的记号以防万一,并使用
    JSON.stringify

  • 我将m_Data变量更改为m_Data=JSON.stringify({getFromDate:““+getFromDate+””,getValueList:[1,2,3]});
    m_Data = JSON.stringify({
      getFromDate: "'" + getFromDate + "'",
      getValueList: [1,2,3]
    });