I have a MediaServiceLoop.svc file that has a function GetMediaLoops that looks like this `
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Xml)]
public string GetMediaLoops()
{
string strFileName = "GetMediaLoops_response.xml";
string strResult = GetFileData(strFileName);
return strResult;
}`
The angular side of code looks like this `
mainApp.factory('MediaService', ['$http', function ($http) {
var factory = {};
factory.getMediaLoops = function () {
return $http.post("http://localhost:62467/MediaLoopService.MediaLoop.svc/GetMediaLoops");
}
return factory;}]);
Controller code:
MediaService.getMediaLoops()
.then(function (response) {
$scope.media = response.data;
}, function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
`
I am able to get a response both in Postman and Chrome Network (
),however I do get the error of "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:2206' is therefore not allowed access." and code flow skips the response and error block in the getMediaLoops angular call.
I have also added in Global.asax file the following piece of code for the above error but still get the above error,Any help would be appreciated
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost");
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();
}
}