跨域 Javascript 访问 WCF 自托管服务时出现 404/405 错误

404/405 Errors With Cross Domain Javascript access to WCF Self hosted Service

我有一个非常简单的 webHttpBinding WCF 服务 运行,它接受 POST。如果我发送 GET - 响应是

Status 405 Method Not Allowed

Response headers Allow: POST Content-Length: 0 Server:

所以该服务正在接收 GET 并响应它只接受 POST 这是正确的。如果我然后发送 POST 我得到这个:

Status 404 Not Found

Response headers Content-Length: 0 Server: Microsoft-HTTPAPI/2.0

WCF 服务配置在这里:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

  <system.web>
    <compilation debug="true" />
  </system.web>    
  <system.serviceModel>
    <services>
      <service name="RaptorHTTPService.RaptorHTTPService">
        <endpoint address="RaptorHTTPService" behaviorConfiguration="WebBehaviour" binding="webHttpBinding" bindingConfiguration="crossDomain" contract="RaptorHTTPService.IRaptorHTTPService" name="WebEndpoint">         
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://ccs-labs.com:8008/RaptorHTTPService/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="crossDomain" crossDomainScriptAccessEnabled="true" allowCookies="true"  />
      </webHttpBinding>
    </bindings>
    <behaviors>      
      <endpointBehaviors>
        <behavior name="WebBehaviour">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior>         
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>          
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>

界面是这样的:

namespace RaptorHTTPService
{

    [ServiceContract]    
    public interface IRaptorHTTPService
    {
        [OperationContract(IsOneWay = true)]
        [WebInvoke(UriTemplate = "SendData/{srcUrl}", Method = "POST", RequestFormat = WebMessageFormat.Xml)]        
        void GetData(string srcUrl);
    }      
}

我在 Chrome 上使用 Advanced Rest Client 进行测试我将有效载荷发送到:http://ccs-labs.com:8008/RaptorHTTPService/Service1/SendData/ 有效载荷是 http://www.google.co.uk

任何人都可以看到哪里出了问题并向我解释问题吗?

而不是通过 http://ccs-labs.com:8008/RaptorHTTPService/Service1/SendData/ 访问它似乎使用 http://ccs-labs.com:8008/RaptorHTTPService/Service1/mex 确实有效。

知道为什么吗?