0
我想打电话给在asp.net使用jQuery WCF服务在asp.net从jQuery的调用WCF服务
WCF服务和asp.net网站是同一个解决方案下,但他们在不同的端口上运行如下面
WCF - http://127.0.0.1:54443/Service1.svc/
asp.net - http://127.0.0.1:57484/WebSite2/
下面是WCF功能码
[WebInvoke(Method = "GET",RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)]
public List<string> getCurrentTime()
{
List<string> lstrSampleDate = new List<string>();
lstrSampleDate.Add(DateTime.Now.TimeOfDay.ToString());
return lstrSampleDate;
}
和下面是jQuery代码
$.ajax({
type: "GET",
url: "http://127.0.0.1:54443/Service1.svc/getCurrentTime",
// crossDomain: true,
datatype: "json",
success: function (rVal) {
//console.log
alert(rVal);
},
error: function (xhr, status) {
//console.log
alert('Error: ' + xhr.statusText + 'Status: ' + xhr.status);
},
complete: function (xhr, status) {
//console.log
alert("The request is completed!");
}
});
当我执行的代码,我得到下面的错误控制台
> XMLHttpRequest cannot load > http://127.0.0.1:54443/Service1.svc/getCurrentTime. Origin > http://127.0.0.1:57484 is not allowed by Access-Control-Allow-Origin.
得到印刷作为一种变通我没有添加下面的设置来配置
(网站)文件<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
仍然没有得到任何有成效的结果。任何人都可以指出我失踪的地方吗?
注:我把它换成“本地主机” 127.0.0.1与感谢