WCF Service throws Http404 on any request except .svc

天涯浪子 提交于 2019-12-25 04:33:19

问题


I have created a WCF Service Library in MVC project and set up MySerice.svc and Web.Config file in project as follow:

<!--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-->

The problem is when I run MySerice.svc file in browser it works fine but all other request made on http://localost:18457/MyService.svc/Anyrequest shows the error which is as like below: (Note: discard the svc file name and supplied url on picture)

I will appreciate if anyone can provide some code snippet. Thank you


回答1:


Luckily I got the answer changing RouteConfig.Cs file as follows From

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

To

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

as long as you should place your .svc file in root of your application.

It worked for me like a charm. Hope it will help to somebody !! Good Luck



来源:https://stackoverflow.com/questions/41113319/wcf-service-throws-http404-on-any-request-except-svc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!