我有一個WCF服務,這是我最好調用一個方法:跨域調用WCF服務
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
double?[] GetPoints(string tourname);
我檢查通過WCF測試客戶端,它工作正常
所以我需要從html頁面調用這個方法。它應該從跨域的其他計算機上運行。
我寫somethig使用jQuery 1-6-2.min.js:
var varType;
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
function CallService() {
alert("CallService");
$.ajax({
type : varType, //GET or POST or PUT or DELETE verb
url : varUrl, // Location of the service
data : varData, //Data sent to server
contentType : varContentType, // content type sent to server
dataType : varDataType, //Expected data format from server
processdata : varProcessData, //True or False
success : function(msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
function Start() {
varType = "POST";
varUrl = "http://localhost:1592/TourService.svc/GetPoints";
varData = '{"tourname ":"customname"}';
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = true;
CallService();
}
function ServiceSucceeded(result) {
alert("ServiceSucceeded");
alert(result);
}
function ServiceFailed(result) {
alert('Service call failed: ' + result.status + ' ' + result.statusText);
varType = null;
varUrl = null;
varData = null;
varContentType = null;
varDataType = null;
varProcessData = null;
}
但是ServiceFailed函數調用時使用提示 「服務調用失敗0錯誤」
如何使一個跨WCF服務的調用域?(使用jQuery與否)
感謝
爲什麼你認爲跨域調用的是什麼問題?並且請更好地分析錯誤發生的位置。消息「0錯誤」僅表明原始錯誤消息未正確轉發給jQuery錯誤回調。 – Codo