我一直在尝试在ASP.NET Web应用程序(servera)和ASP.NET SOAP UI(serverb)之间启用CORS。发生了从Web应用程序到SOAP的请求,但是SOAP服务以错误返回(在Google Chrome中):
从原点“ http://serverb/service.svc/”到“ http://servera”的XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP正常状态。
我可以访问客户端Web应用程序和SOAP服务。
我的SOAP服务UI Web.config具有以下部分来启用CORS:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://servera" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="origin, content-type, accept, x-requested-with" />
<add name="Access-Control-Max-Age" value="3600" />
</customHeaders>
</httpProtocol>
该请求是通过cshtml页面中的AJAX调用完成的:
$.ajax({
url: "http://serverb/service.svc",
type: "POST",
dataType: "text",
data: soapRequest,
contentType: "application/xml",
success: function(data) {
console.log(data);
//response(data);
return "";
},
error: function (request, status, error)
{
console.log("Error: " + error + " Status: " + status);
}
});
我尝试通过添加Global.asax文件来添加代码来处理请求,但是Global.asax.cs代码未触发。
Web客户端和SOAP UI均在Windows 8的IIS上运行。
任何帮助将不胜感激。