{"id":219895,"date":"2014-04-18T13:19:03","date_gmt":"2014-04-18T09:19:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=219895"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=219895","title":{"rendered":"<span class=\"post_title\">WCF + Cross Domain Ajax Calls (CORS) + \u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c!<br \/>  \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 WCF \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u043e\u0432. \u041d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u043c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u0431\u044b\u043b\u0430 \u0438\u043b\u0438 \u043d\u0435\u043f\u043e\u043b\u043d\u043e\u0439, \u0438\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0430 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u044f\u044e\u0449\u0435\u0439 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0425\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f WCF \u0438 AJAX POST \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0445 \u0432 \u0441\u0435\u0431\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e Cookies \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a AJAX \u0432\u044b\u0437\u043e\u0432 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u043e\u043c\u0435\u043d \u043d\u0435 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0432 \u0441\u0438\u043b\u0443 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0431\u044b\u043b \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d \u0438 \u0440\u0435\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 CORS(<a href=\"http:\/\/en.wikipedia.org\/wiki\/Cross-origin_resource_sharing\">wiki<\/a>, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/HTTP\/Access_control_CORS\">mozilla<\/a>). \u042d\u0442\u043e\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0445 HTTP \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u0423\u043f\u0440\u043e\u0449\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0430 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<p>  \u041a\u043b\u0438\u0435\u043d\u0442(\u0431\u0440\u0430\u0443\u0437\u0435\u0440) \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441 HTTP \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c <code>Origin<\/code>, \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Access-Control-Allow-Origin<\/code>. \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0430\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\/\u043e\u0442\u0432\u0435\u0442 \u0441 \u0430\u0434\u0440\u0435\u0441\u0430 <code>http:\/\/foo.example<\/code> \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441 <code>http:\/\/bar.other\/resources\/public-data\/<\/code>:  <\/p>\n<blockquote><p>\u0417\u0430\u043f\u0440\u043e\u0441:<br \/>  GET \/resources\/public-data\/ HTTP\/1.1<br \/>  Host: bar.other<br \/>  Origin: <code>http:\/\/foo.example<\/code><br \/>  [\u0414\u0440\u0443\u0433\u0438\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438]<\/p>\n<p>  \u041e\u0442\u0432\u0435\u0442:<br \/>  HTTP\/1.1 200 OK<br \/>  Date: Mon, 01 Dec 2008 00:23:53 GMT<br \/>  Access-Control-Allow-Origin: *<br \/>  Content-Type: application\/xml<\/p>\n<p>  [XML Data]  <\/p><\/blockquote>\n<h5>\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438<\/h5>\n<p>  <\/p>\n<ul>\n<li><code>Access-Control-Allow-Origin<\/code> \u2014 \u0434\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0441 \u043a\u0430\u043a\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u041c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <code>*<\/code> \u0438\u043b\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0434\u043e\u043c\u0435\u043d, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>http:\/\/foo.example<\/code>. \u0414\u0430\u043d\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d, \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442.\u0435. \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u043c\u0435\u043d\u043e\u0432 \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. <\/li>\n<li><code>Access-Control-Allow-Headers<\/code> \u2014 \u044d\u0442\u043e\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c. \u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438: <code>POST,GET,OPTIONS<\/code>, \u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 <code>PUT<\/code>, \u0438 <code>DELETE<\/code>, \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/li>\n<li><code>Access-Control-Allow-Headers<\/code> \u2014 \u044d\u0442\u043e\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>Content-Type<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0437\u0430\u0434\u0430\u0442\u044c \u0442\u0438\u043f \u043e\u0442\u0432\u0435\u0442\u0430 <code>application\/json<\/code>.<\/li>\n<li><code>Access-Control-Allow-Credentials<\/code> \u2014 \u044d\u0442\u043e\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c Cookie \u0438 Authorization \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>true <\/code>\u0438 <code>false<\/code>. <b>\u0412\u0430\u0436\u043d\u043e:<\/b> \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 <code>Access-Control-Allow-Origin<\/code> \u0431\u0443\u0434\u0435\u0442 \u044f\u0432\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0434\u043e\u043c\u0435\u043d, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>*<\/code> \u2014 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d.<\/li>\n<\/ul>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0431\u0440\u0430\u0443\u0437\u0435\u0440. \u0415\u0441\u043b\u0438 \u0435\u043c\u0443 \u0447\u0442\u043e-\u0442\u043e \u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445, \u043e\u043d \u043d\u0435 \u043e\u0442\u0434\u0430\u0441\u0442 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e(\u0435\u0441\u043b\u0438 \u043d\u0435 \u0432\u0435\u0440\u043d\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 <code>Access-Control-Allow-Headers<\/code>, \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d <code>Access-Control-Allow-Credentials<\/code> \u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 <code>Access-Control-Allow-Origin<\/code>. \u041f\u0435\u0440\u0435\u0434 <code>POST<\/code> \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0434\u043e\u043c\u0435\u043d, \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442 <code>OPTIONS<\/code> \u0437\u0430\u043f\u0440\u043e\u0441(<i>preflight request<\/i>) \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c. <\/p>\n<h5>WCF<\/h5>\n<p>  \u041f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e\u0433\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, WCF \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u043e\u0434\u043d\u0430\u043a\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u0435\u043c\u044b. \u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<h6>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c web.config.<\/h6>\n<p>  \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u043f\u0440\u044f\u043c\u043e \u0432 web.config.  <\/p>\n<pre><code>&lt;system.webServer&gt;  &lt;httpProtocol&gt;   &lt;customHeaders&gt;    &lt;add name=&quot;Access-Control-Allow-Origin&quot; value=&quot;http:\/\/foo.example&quot; \/&gt;    &lt;add name=&quot;Access-Control-Allow-Headers&quot; value=&quot;Content-Type&quot; \/&gt;    &lt;add name=&quot;Access-Control-Allow-Methods&quot; value=&quot;POST, GET, OPTIONS&quot; \/&gt;    &lt;add name=&quot;Access-Control-Allow-Credentials&quot; value=&quot;true&quot; \/&gt;   &lt;\/customHeaders&gt;  &lt;\/httpProtocol&gt; &lt;\/system.webServer&gt;<\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u043e\u0439 \u0438 \u043d\u0435\u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c\u044e. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u043e\u0432 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u043e\u043d \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442 CORS \u043d\u0430 \u0432\u0435\u0441\u044c \u0441\u0430\u0439\u0442(\u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435).<\/p>\n<h6>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Global.asax<\/h6>\n<p>  \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432 Global.asax.cs \u043a\u043e\u0434\u0430, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441.   <\/p>\n<pre><code>protected void Application_BeginRequest(object sender, EventArgs e) { \tvar allowedOrigins = new [] { &quot;http:\/\/foo.example&quot;, &quot;http:\/\/bar.example&quot; }; \tvar request = HttpContext.Current.Request; \tvar response = HttpContext.Current.Response; \tvar origin = request.Headers[&quot;Origin&quot;];  \tif (origin != null && allowedOrigins.Any(x =&gt; x == origin)) { \t\tresponse.AddHeader(&quot;Access-Control-Allow-Origin&quot;, origin); \t\tresponse.AddHeader(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, POST, OPTIONS&quot;); \t\tresponse.AddHeader(&quot;Access-Control-Allow-Headers&quot;, &quot;Content-Type, X-Requested-With&quot;); \t\tresponse.AddHeader(&quot;Access-Control-Allow-Credentials&quot;, &quot;true&quot;); \t\tif (request.HttpMethod == &quot;OPTIONS&quot;) { \t\t\tresponse.End(); \t\t} \t} } <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u043c\u0435\u043d\u043e\u0432, \u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0435\u0441\u044c \u0441\u0430\u0439\u0442. \u0411\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0443\u0442 \u0436\u0435, \u043d\u043e \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u044d\u0442\u043e \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u043e \u0441 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430\u043c\u0438 \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<h6>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u0432 \u0432 \u043a\u043e\u0434\u0435 WCF \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h6>\n<p>  \u0414\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0442\u0435\u043c, \u0447\u0442\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u0430. \u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code>[ServiceContract] public class MyService {      [OperationContract]     [WebInvoke(Method = &quot;POST&quot;, ...)]     public string DoStuff() {          AddCorsHeaders();          return &quot;&lt;Data&gt;&quot;;      }      private void AddCorsHeaders() {         var allowedOrigins = new [] { &quot;http:\/\/foo.example&quot;, &quot;http:\/\/bar.example&quot; };         var request = WebOperationContext.Current.IncomingRequest;         var response = WebOperationContext.Current.OutgoingResponse;         var origin = request.Headers[&quot;Origin&quot;];          if (origin != null && allowedOrigins.Any(x =&gt; x == origin)) {             response.AddHeader(&quot;Access-Control-Allow-Origin&quot;, origin);             response.AddHeader(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, POST, OPTIONS&quot;);             response.AddHeader(&quot;Access-Control-Allow-Headers&quot;, &quot;Content-Type, X-Requested-With&quot;);             response.AddHeader(&quot;Access-Control-Allow-Credentials&quot;, &quot;true&quot;);             if (request.HttpMethod == &quot;OPTIONS&quot;) {                 response.End();             }         }     } } <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 CORS \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u043c\u0435\u0442\u043e\u0434\u0430. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u2014 \u0432\u044b\u0437\u043e\u0432 <code>AddCorsHeaders<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u041f\u043b\u044e\u0441 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<h6>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 EndPointBehavior \u0438 DispatchMessageInspector <\/h6>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 WCF \u043f\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<br \/>  \u0421\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f 2 \u043a\u043b\u0430\u0441\u0441\u0430 <code>EnableCorsBehavior<\/code>:  <\/p>\n<pre><code>using System; using System.ServiceModel.Channels; using System.ServiceModel.Configuration; using System.ServiceModel.Description; using System.ServiceModel.Dispatcher;  namespace My.Web.Cors {     public class EnableCorsBehavior : BehaviorExtensionElement, IEndpointBehavior {         public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { }         public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { }         public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) {             endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new EnableCorsMessageInspector());         }         public void Validate(ServiceEndpoint endpoint) { }         public override Type BehaviorType {             get { return typeof(EnableCorsBehavior); }         }         protected override object CreateBehavior() {             return new EnableCorsBehavior();         }     } }<\/code><\/pre>\n<p>  \u0438 <code>EnableCorsMessageInspector<\/code>:  <\/p>\n<pre><code>using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Dispatcher;  namespace My.Web.Cors {     public class EnableCorsMessageInspector : IDispatchMessageInspector {         public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { \t\t    var allowedOrigins = new [] { &quot;http:\/\/foo.example&quot;, &quot;http:\/\/bar.example&quot; };             var httpProp = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];             if (httpProp != null) {                 string origin = httpProp.Headers[&quot;Origin&quot;];                 if (origin != null && allowedOrigins.Any(x =&gt; x == origin)) {                   return origin;                 }             }             return null;         }         public void BeforeSendReply(ref Message reply, object correlationState) {             string origin = correlationState as string;             if (origin != null) {                 HttpResponseMessageProperty httpProp = null;                 if (reply.Properties.ContainsKey(HttpResponseMessageProperty.Name)) {                   httpProp = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name];                 } else {                   httpProp = new HttpResponseMessageProperty();                   reply.Properties.Add(HttpResponseMessageProperty.Name, httpProp);                 }                 httpProp.Headers.Add(&quot;Access-Control-Allow-Origin&quot;, origin);                 httpProp.Headers.Add(&quot;Access-Control-Allow-Credentials&quot;, &quot;true&quot;);                 httpProp.Headers.Add(&quot;Access-Control-Request-Method&quot;, &quot;POST,GET,OPTIONS&quot;);                 httpProp.Headers.Add(&quot;Access-Control-Allow-Headers&quot;, &quot;X-Requested-With,Content-Type&quot;);             }         }     } } <\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>web.config<\/code> \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 <code>EnableCorsBehavior<\/code>:  <\/p>\n<pre><code>&lt;system.serviceModel&gt; ... \t&lt;extensions&gt; \t\t&lt;behaviorExtensions&gt;         \t\t\t&lt;add name=&quot;crossOriginResourceSharingBehavior&quot; type=&quot;My.Web.Cors.EnableCorsBehavior, My.Web, Version=1.0.0.0, Culture=neutral&quot; \/&gt;         \t\t&lt;\/behaviorExtensions&gt;       \t&lt;\/extensions&gt; ... &lt;\/system.serviceModel&gt; <\/code><\/pre>\n<p>  \u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0435 \u0434\u043b\u044f <code>EnableCorsBehavior <\/code>\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e <code>Behaviour<\/code> \u043d\u0430\u0448\u0435\u0433\u043e <code>Endpoint<\/code>&#8216;a  <\/p>\n<pre><code>&lt;system.serviceModel&gt;     &lt;services&gt;         &lt;service name=&quot;My.Web.Services.MyService&quot;&gt;             &lt;endpoint address=&quot;&quot; behaviorConfiguration=&quot;My.Web.Services.MyService&quot; binding=&quot;webHttpBinding&quot; contract=&quot;My.Web.Services.MyService&quot; \/&gt;         &lt;\/service&gt;     &lt;\/services&gt; \t... \t&lt;behaviors&gt; \t\t... \t\t&lt;endpointBehaviors&gt; \t\t\t... \t\t\t&lt;behavior name=&quot;My.Web.Services.MyService&quot;&gt; \t\t\t\t&lt;webHttp\/&gt; \t\t\t\t&lt;crossOriginResourceSharingBehavior \/&gt; &lt;!-- \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 --&gt; \t\t\t&lt;\/behavior&gt; \t\t\t... \t\t&lt;\/endpointBehaviors&gt; \t\t... \t&lt;\/behaviours&gt; \t... &lt;\/system.serviceModel&gt;<\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>OPTIONS<\/code>. \u0412 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442: \u0432 \u0442\u0435\u043b\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a <code>OPTIONS <\/code>\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.  <\/p>\n<pre><code>[OperationContract] [WebInvoke(Method = &quot;OPTIONS&quot;, UriTemplate = &quot;*&quot;)] public void GetOptions() {     \/\/ \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442\u0441\u044f \u0432 EnableCorsMessageInspector  } <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 WCF \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 preflight \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u043e\u0431 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043d\u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <code>GetOptions<\/code> \u0432 \u0442\u0435\u043b\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043d\u0435\u043c\u0430\u043b\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043b\u043e\u0433\u0438\u043a\u0443 \u043a\u043e\u043c\u043c\u0443\u043d\u0438\u043a\u0430\u0446\u0438\u0438. <\/p>\n<h5>\u041f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e Javascript \u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430\u0445 <\/h5>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0438 Cookie \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u0432 XmlHttpRequest \u0431\u044b\u043b \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 <code>true<\/code> \u0444\u043b\u0430\u0433 <code>withCredentials<\/code>. \u0414\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 jQuery \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b c AJAX, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043d\u0435\u0433\u043e:  <\/p>\n<pre><code> $.ajax({             type: 'POST',             cache: false,             dataType: 'json',             xhrFields: {                 withCredentials: true             },             contentType: 'application\/json; charset=utf-8',             url: options.serviceUrl + '\/DoStuff'         }); <\/code><\/pre>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u043b\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 IE10, \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u044b IE8\/9 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0434\u0430\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 GET \u0438 POST.<\/p>\n<h6>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/h6>\n<p>  \u0412\u043e \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445 \u0432\u044b\u0448\u0435 \u043d\u0435\u044f\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430. \u0418\u043c\u0435\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435 <code>http:\/\/bar.other<\/code>, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e Ajax \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u0441 \u0441\u0430\u0439\u0442\u0430 <code>http:\/\/foo.example<\/code>. \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0438 \u0440\u0435\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043d\u0430\u0445\u043e\u0434\u044f\u0441\u044c \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u0430\u0439\u0442\u043e\u0432, \u0436\u0438\u0432\u0443\u0449\u0438\u0445 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0433\u043e \u0431\u0438\u0437\u043d\u0435\u0441 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u0430\u0445 \u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445. \u041a\u0430\u043a \u0443\u0436\u0435 \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0442\u0443\u0442 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a <code>Access-Control-Allow-Credentials<\/code> \u0438 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f <code>XmlHttpRequest<\/code> \u0444\u043b\u0430\u0433\u0430 <code>withCredentials=true<\/code>.<\/p>\n<h6>\u0421\u043f\u0438\u0441\u043e\u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/h6>\n<p>  <\/p>\n<ul>\n<li><a href=\"http:\/\/code.msdn.microsoft.com\/windowsdesktop\/Implementing-CORS-support-c1f9cd4b\">code.msdn.microsoft.com\/windowsdesktop\/Implementing-CORS-support-c1f9cd4b<\/a> \u2014 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043b\u043d\u043e\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 MessageInspector \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 <a href=\"http:\/\/blogs.msdn.com\/b\/carlosfigueira\/archive\/2012\/05\/15\/implementing-cors-support-in-wcf.aspx?Redirected=true\">\u0441\u0442\u0430\u0442\u044c\u044f <\/a>\u043a \u043d\u0435\u0439<\/li>\n<li><a href=\"http:\/\/enable-cors.org\/server_wcf.html\">enable-cors.org\/server_wcf.html<\/a> \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0439 \u043c\u0430\u043d\u0443\u0430\u043b \u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e Behavior \u0438 MessageInspector, \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 OPTIONS \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0438 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443\/\u0432\u044b\u0431\u043e\u0440 \u0434\u043e\u043c\u0435\u043d\u0430 Origin<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/HTTP\/Access_control_CORS#Access-Control-Allow-Headers\">developer.mozilla.org\/en-US\/docs\/HTTP\/Access_control_CORS#Access-Control-Allow-Headers<\/a> \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e CORS<\/li>\n<\/ul>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/219895\/\"> http:\/\/habrahabr.ru\/post\/219895\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c!<br \/>  \u0425\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 WCF \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0434\u043e\u043c\u0435\u043d\u043e\u0432. \u041d\u0430\u0439\u0434\u0435\u043d\u043d\u0430\u044f \u043c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435 \u0431\u044b\u043b\u0430 \u0438\u043b\u0438 \u043d\u0435\u043f\u043e\u043b\u043d\u043e\u0439, \u0438\u043b\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0430 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0437\u0430\u0442\u0440\u0443\u0434\u043d\u044f\u044e\u0449\u0435\u0439 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \u0425\u043e\u0447\u0443 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f WCF \u0438 AJAX POST \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0445 \u0432 \u0441\u0435\u0431\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e Cookies \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-219895","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/219895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=219895"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/219895\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=219895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=219895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=219895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}