WCF 服务对除 .svc 之外的任何请求抛出 Http404 [英] WCF Service throws Http404 on any request except .svc

查看:31
本文介绍了WCF 服务对除 .svc 之外的任何请求抛出 Http404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

问题是当我在浏览器中运行 MySerice.svc 文件时它工作正常但所有其他请求在

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

推荐答案

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

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

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

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

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

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

这篇关于WCF 服务对除 .svc 之外的任何请求抛出 Http404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆