rest api wcf enable cors method not allowed












1















I have below in wcf webconfig



 <httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000"/>
</customHeaders>
</httpProtocol>


service



 [OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "getItem", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[Description("Fetch item from database.")]


Angular 6 calling



this.http.post('http://localhost:49823/service.svc/getItem?authkey=key',
{
json data
}
).subscribe(data => {console.log(data) },err => {
console.log(err);
});


Interceptor



request = request.clone({
setHeaders: {
'Content-Type': 'application/json'
}
});


It throws error




Access to XMLHttpRequest at
'http://localhost:49823/service.svc/getitem?authkey=key5' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: It does not have
HTTP ok status.




WCF service running on 49823 and angular 6 running on 4200.



Couldn't figure what is causing issue as already enable cors in wcf.



This is working fine in POSTMAN










share|improve this question























  • It works fine with Postman because you’re not having Postman send an OPTIONS request. But your browser is sending an OPTIONS request — a CORS preflight OPTIONS request — first before trying the POST request from your code. And the preflight fails so the browser stops right there and never even attempts to send the POST request from your code. And that preflight fails because the response from http://localhost:49823/service.svc/getItem?authkey=key to the OPTIONS request isn’t a 200 OK but is instead some 4xx or 5xx error.

    – sideshowbarker
    2 days ago













  • So how to resolve this

    – Md. Parvez Alam
    2 days ago











  • I called other web api from this angular call, and it is working but call to wcf not working

    – Md. Parvez Alam
    2 days ago











  • Did you check if access-control-allow-origin header is getting passed?

    – Manoj Choudhari
    16 hours ago
















1















I have below in wcf webconfig



 <httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000"/>
</customHeaders>
</httpProtocol>


service



 [OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "getItem", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[Description("Fetch item from database.")]


Angular 6 calling



this.http.post('http://localhost:49823/service.svc/getItem?authkey=key',
{
json data
}
).subscribe(data => {console.log(data) },err => {
console.log(err);
});


Interceptor



request = request.clone({
setHeaders: {
'Content-Type': 'application/json'
}
});


It throws error




Access to XMLHttpRequest at
'http://localhost:49823/service.svc/getitem?authkey=key5' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: It does not have
HTTP ok status.




WCF service running on 49823 and angular 6 running on 4200.



Couldn't figure what is causing issue as already enable cors in wcf.



This is working fine in POSTMAN










share|improve this question























  • It works fine with Postman because you’re not having Postman send an OPTIONS request. But your browser is sending an OPTIONS request — a CORS preflight OPTIONS request — first before trying the POST request from your code. And the preflight fails so the browser stops right there and never even attempts to send the POST request from your code. And that preflight fails because the response from http://localhost:49823/service.svc/getItem?authkey=key to the OPTIONS request isn’t a 200 OK but is instead some 4xx or 5xx error.

    – sideshowbarker
    2 days ago













  • So how to resolve this

    – Md. Parvez Alam
    2 days ago











  • I called other web api from this angular call, and it is working but call to wcf not working

    – Md. Parvez Alam
    2 days ago











  • Did you check if access-control-allow-origin header is getting passed?

    – Manoj Choudhari
    16 hours ago














1












1








1


1






I have below in wcf webconfig



 <httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000"/>
</customHeaders>
</httpProtocol>


service



 [OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "getItem", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[Description("Fetch item from database.")]


Angular 6 calling



this.http.post('http://localhost:49823/service.svc/getItem?authkey=key',
{
json data
}
).subscribe(data => {console.log(data) },err => {
console.log(err);
});


Interceptor



request = request.clone({
setHeaders: {
'Content-Type': 'application/json'
}
});


It throws error




Access to XMLHttpRequest at
'http://localhost:49823/service.svc/getitem?authkey=key5' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: It does not have
HTTP ok status.




WCF service running on 49823 and angular 6 running on 4200.



Couldn't figure what is causing issue as already enable cors in wcf.



This is working fine in POSTMAN










share|improve this question














I have below in wcf webconfig



 <httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
<add name="Access-Control-Max-Age" value="1728000"/>
</customHeaders>
</httpProtocol>


service



 [OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "getItem", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[Description("Fetch item from database.")]


Angular 6 calling



this.http.post('http://localhost:49823/service.svc/getItem?authkey=key',
{
json data
}
).subscribe(data => {console.log(data) },err => {
console.log(err);
});


Interceptor



request = request.clone({
setHeaders: {
'Content-Type': 'application/json'
}
});


It throws error




Access to XMLHttpRequest at
'http://localhost:49823/service.svc/getitem?authkey=key5' from origin
'http://localhost:4200' has been blocked by CORS policy: Response to
preflight request doesn't pass access control check: It does not have
HTTP ok status.




WCF service running on 49823 and angular 6 running on 4200.



Couldn't figure what is causing issue as already enable cors in wcf.



This is working fine in POSTMAN







angular wcf cors wcf-rest-starter-kit






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Md. Parvez AlamMd. Parvez Alam

1,86621336




1,86621336













  • It works fine with Postman because you’re not having Postman send an OPTIONS request. But your browser is sending an OPTIONS request — a CORS preflight OPTIONS request — first before trying the POST request from your code. And the preflight fails so the browser stops right there and never even attempts to send the POST request from your code. And that preflight fails because the response from http://localhost:49823/service.svc/getItem?authkey=key to the OPTIONS request isn’t a 200 OK but is instead some 4xx or 5xx error.

    – sideshowbarker
    2 days ago













  • So how to resolve this

    – Md. Parvez Alam
    2 days ago











  • I called other web api from this angular call, and it is working but call to wcf not working

    – Md. Parvez Alam
    2 days ago











  • Did you check if access-control-allow-origin header is getting passed?

    – Manoj Choudhari
    16 hours ago



















  • It works fine with Postman because you’re not having Postman send an OPTIONS request. But your browser is sending an OPTIONS request — a CORS preflight OPTIONS request — first before trying the POST request from your code. And the preflight fails so the browser stops right there and never even attempts to send the POST request from your code. And that preflight fails because the response from http://localhost:49823/service.svc/getItem?authkey=key to the OPTIONS request isn’t a 200 OK but is instead some 4xx or 5xx error.

    – sideshowbarker
    2 days ago













  • So how to resolve this

    – Md. Parvez Alam
    2 days ago











  • I called other web api from this angular call, and it is working but call to wcf not working

    – Md. Parvez Alam
    2 days ago











  • Did you check if access-control-allow-origin header is getting passed?

    – Manoj Choudhari
    16 hours ago

















It works fine with Postman because you’re not having Postman send an OPTIONS request. But your browser is sending an OPTIONS request — a CORS preflight OPTIONS request — first before trying the POST request from your code. And the preflight fails so the browser stops right there and never even attempts to send the POST request from your code. And that preflight fails because the response from http://localhost:49823/service.svc/getItem?authkey=key to the OPTIONS request isn’t a 200 OK but is instead some 4xx or 5xx error.

– sideshowbarker
2 days ago







It works fine with Postman because you’re not having Postman send an OPTIONS request. But your browser is sending an OPTIONS request — a CORS preflight OPTIONS request — first before trying the POST request from your code. And the preflight fails so the browser stops right there and never even attempts to send the POST request from your code. And that preflight fails because the response from http://localhost:49823/service.svc/getItem?authkey=key to the OPTIONS request isn’t a 200 OK but is instead some 4xx or 5xx error.

– sideshowbarker
2 days ago















So how to resolve this

– Md. Parvez Alam
2 days ago





So how to resolve this

– Md. Parvez Alam
2 days ago













I called other web api from this angular call, and it is working but call to wcf not working

– Md. Parvez Alam
2 days ago





I called other web api from this angular call, and it is working but call to wcf not working

– Md. Parvez Alam
2 days ago













Did you check if access-control-allow-origin header is getting passed?

– Manoj Choudhari
16 hours ago





Did you check if access-control-allow-origin header is getting passed?

– Manoj Choudhari
16 hours ago












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54252572%2frest-api-wcf-enable-cors-method-not-allowed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54252572%2frest-api-wcf-enable-cors-method-not-allowed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown