【问题标题】:WCF Service throws Http404 on any request except .svcWCF 服务在除 .svc 之外的任何请求上引发 Http404
【发布时间】:2016-12-13 03:33:39
【问题描述】:

我在 MVC 项目中创建了一个 WCF 服务库,并在项目中设置了 MySerice.svc 和 Web.Config 文件如下:

<!--added to run WCF service -->
<system.serviceModel>
  <!-- this multipleSiteBindingsEnabled for remote access -->
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="True" />
  <services>
    <service name="SchoolProject.WCF.SchoolProjectService" behaviorConfiguration="ServiceBehaviour">
     

      <endpoint address="" binding="webHttpBinding" contract="SchoolProject.WCF.ISchoolProjectService" behaviorConfiguration="web" />
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehaviour">
        <serviceMetadata httpGetEnabled="True" />
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="web">
        <webHttp/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
</system.serviceModel>


<!-- end-->

问题是当我在浏览器中运行 MySerice.svc 文件时它工作正常,但在 http://localost:18457/MyService.svc/Anyrequest 上发出的所有其他请求都显示如下错误:(注意:丢弃图片上的 svc 文件名和提供的 url)

如果有人能提供一些代码 sn-p,我将不胜感激。谢谢

【问题讨论】:

    标签: c# wcf wcf-data-services


    【解决方案1】:

    幸运的是,我得到了更改 RouteConfig.Cs 文件的答案,如下所示 来自

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    

    routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
    

    只要您应该将 .svc 文件放在应用程序的根目录中即可。

    它对我来说就像一种魅力。希望它会对某人有所帮助!祝你好运

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 2016-01-28
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多