I am very new in angular. Right now I am having some problem on angular POST to WCF.
This is the WCF contract :
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate = "/InsertJSONSTRING/")]
void InsertJSONSTRING(DyeMaster value);
This is the angular controller
app.controller('UploadCOJSON', function ($scope, $http) {
$scope.SendData = function () {
function DYE() {
this.DESCRIPTION;
this.COLOR_CODE;
}
$scope.dye = new DYE();
$scope.dye.DESCRIPTION = $scope.DESCRIPTION;
$scope.dye.COLOR_CODE = $scope.COLOR_CODE;
var dataR = JSON.stringify($scope.dye);
$http({
url: "http://localhost:63599/ServiceMobileListener.svc/InsertJSONSTRING",
method: "POST",
data: dataR,
dataType: "json",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
});
}
});
This is the error :
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:63599/ServiceMobileListener.svc/InsertJSONSTRING. This can be fixed by moving the resource to the same domain or enabling CORS.
Somehow when I excluding the parameter (data) , it is working without any error.
$http({
url: "http://localhost:63599/ServiceMobileListener.svc/InsertJSONSTRING",
method: "POST",
dataType: "json",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
});
Note : Enabling CORS as per described here http://enable-cors.org/server_wcf.html has been implemented
Appreciate your kind helps.