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

时间:2015-06-07 09:05:08

标签: javascript c# wcf

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

  

状态405方法不允许

     

响应标头允许:POST内容长度:0服务器:

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

  

找不到状态404

     

响应标头内容长度:0服务器: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

任何人都可以看到出错的地方并向我解释问题吗?

1 个答案:

答案 0 :(得分:0)

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

有什么想法?