由于交叉来源政策,不允许使用wcf服务

时间:2015-07-01 11:22:40

标签: wcf

第一个网址(我的wcf)无法正常工作(当我评论第二个网址时)..但是第二个确实很好(一个开放的API)

    var url = "http://localhost:26770/Service.svc/Employees";
    url = "http://www.omdbapi.com/?t=sam&tomatoes=true&plot=full";
    var response = { success: false, message: 'Error' };
    var req = { method: 'GET', url: url, data: {} };        
    $http(req).success(function (data) {
        if (data != "0")
            response = { success: true, message: 'Wao' };
        else
            response = { success: false, message: 'invalid data' };
        alert(response.message);
    });

http://localhost:26770/Service.svc/Employees对我有用。在浏览器中访问时提供json数据。所以它必须意味着WCF正在运行..但是当我在其他api url工作的应用程序中使用它时。由于交叉原始请求而不允许

我遵循了本教程http://www.codeproject.com/Articles/845474/Enabling-CORS-in-WCF

我将global.asax添加到我的服务应用程序并遵循代码

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
        if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE");

            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
            HttpContext.Current.Response.End();
        }
    }

我重新构建了服务应用程序..测试了其在浏览器中工作的网址..但仍然无法访问来自此wcf服务的结果在我在同一主机上的其他应用中但不同的端口=> (cross domain

0 个答案:

没有答案