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

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

本文关键字:WCF 访问 服务 Javascript 错误      更新时间:2023-09-26

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

状态405方法不允许

响应头允许:POST Content-Length: 0服务器:

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

状态404 Not Found

响应头Content-Length: 0 Server: microsoft - httpi/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上的高级休息客户端进行测试,我正在发送有效载荷到: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确实有效。

知道为什么吗?