2012-08-17 58 views
0

當我嘗試從我的WCF服務加載統計信息時,出現錯誤請求錯誤400。我的電話看起來像這樣。我拿出日期參數來查看是否是原因,但沒有運氣仍然得到相同的錯誤。錯誤的請求 - WCF與jQuery Post

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

你可以瀏覽到你的服務? WebInvoke()沒有方法?你能做到嗎? – 2012-08-17 22:29:23

回答

1

好像你正試圖通過執行AJAX $方法跨域Web服務調用。在這種情況下,您的m_dataType值應該是"jsonp"而不是"json"

類似的問題here