【问题标题】:Bad Request - WCF with jQuery Post错误请求 - 带有 jQ​​uery Post 的 WCF
【发布时间】:2012-08-17 14:57:39
【问题描述】:

我尝试从 WCF 服务加载统计信息时收到错误请求错误 400。我的电话看起来像这样。我拉出了日期参数,看看是否是这个原因,但没有运气仍然得到同样的错误。

function WCFJSON() {
//var now = new Date();
//var getFromDate = dateToWcf(new Date(now - (60000 * 1440)));

var dt = new Date(now);
var dt1 = new Date(Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds()));
var getFromDate = dt1.toMSJSON();

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

Date.prototype.toMSJSON = function () {
var date = '//Date(' + this.getTime() + ')//'; //CHANGED LINE
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 fserver                  
    processdata: m_ProcessData, //True or False
    crossdomain: true,    
    contentType: "application/json; charset=utf-8",             
    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              
});
}

IDashboardWCFService 接口如下所示:

[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();
}

【问题讨论】:

  • 您可以浏览您的服务吗? WebInvoke() 没有方法?你能做到吗?

标签: c# jquery json wcf


【解决方案1】:

您似乎正在尝试通过 $ajax 方法执行跨域 Web 服务调用。在这种情况下,您的 m_dataType 值应该是 "jsonp" 而不是 "json"

类似问题here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    相关资源
    最近更新 更多