除.svc之外的任何请求,WCF服务都会抛出Http404

时间:2016-12-13 03:33:40

标签: c# wcf wcf-data-services

我在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图片) enter image description here

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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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