为 Web 服务设置 IIS

Setting up IIS for Web Service

我无法获得任何允许 javascript 函数使用 Web 服务的教程或设置说明。在我的电脑上,Chrome 只是抛出一个

500 (Internal Server Error)

和 运行 来自服务器的网页,IE 抛出

required Cross Origin Resource Sharing (CORS).

required CORS preflight.

我已经在 webconfig 中添加了所需的跨域设置,但它仍然不起作用。

<configuration>
    <system.web>
      <customErrors mode="Off"/>
      <compilation strict="false" explicit="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5"  />
      <webServices>
        <!-- added because asmx -->
        <protocols>
          <add name="HttpGet"/>
          <add name="HttpPost"/>
        </protocols>
      </webServices>
    </system.web>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

</configuration>

Javascript:

function GetMember() {
    $.ajax({
        type: "POST",
        url: "https://www.mywebsite.org/Callsickapp/Webservice1.asmx/HelloWorld",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnGetMemberSuccess,
        error: OnGetMemberError
    });
}
document.getElementById("btnCallService").onclick = GetMember;
function OnGetMemberSuccess(data, status) {
    //jQuery code will go here...

    document.getElementById("answers").innerHTML= data.d;
}
function OnGetMemberError(request, status, error) {
    //jQuery code will go here...
    document.getElementById("answers").innerHTML= request.statusText
}

我错过了什么?

我只需要实际阅读 Web 服务顶部的评论。vb 由 Visual Studio 生成的文件。

'To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

' <System.Web.Script.Services.ScriptService()> _

简单 "HelloWorld" 网络服务和教程中的其他网络服务现在可以正常工作。