WCF +通配符映射 + IIS6 = 每个方法都出现 404 错误!

发布于 2024-10-06 06:56:56 字数 1600 浏览 2 评论 0原文

当启用通配符映射时,在 IIS6 上执行 WCF 方法时,我收到 404。

您可以通过在 VS2008 中创建新的 WCF 服务(新项目 > WCF 服务应用程序)来重现这一点。浏览到虚拟方法(“GetData”)...您会注意到它返回 400...这很好,因为它显示它仍在转发到 WCF。

但是:如果您在 IIS6 中启用通配符映射,您现在将收到 404,这意味着 WCF 不再拦截请求。

我的代码如下:

[ServiceContract]
public interface IRest {
    [OperationContract]
    [WebGet(UriTemplate = "/test")]
    int Test();
}

使用以下 web.config:

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="ServiceX.RestBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="ServiceX.RestBehavior">
        <serviceMetadata httpGetEnabled="false" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />

  <services>
    <service behaviorConfiguration="ServiceX.RestBehavior"
      name="ServiceX.Rest">
      <endpoint address="" behaviorConfiguration="ServiceX.RestBehavior"
        binding="webHttpBinding" contract="ServiceX.IRest" />
    </service>
  </services>
</system.serviceModel>

无需通配符映射,一切正常;我可以浏览到“/services/rest.svc/test”,我将收到预期的结果。

但是,一旦我启用通配符映射(.* > C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll),当我尝试访问方法时,我就会开始收到 404 错误(尽管我可以仍然查看“/services/rest.svc”)。

我已经用尽了 Google 和 StackOverflow :(

I am receiving 404s when executing a WCF method on IIS6 when wildcard mapping is enabled.

You can all reproduce this by creating a new WCF Service in VS2008 (new Project > WCF Service Application). Browse to the dummy method ('GetData')... you will notice it returns 400... that's fine because it shows it's still forwarding to WCF.

However: if you enable wildcard mapping in IIS6 you will now get a 404, meaning WCF is no longer intercepting the request.

My code is as follows:

[ServiceContract]
public interface IRest {
    [OperationContract]
    [WebGet(UriTemplate = "/test")]
    int Test();
}

With the following web.config:

<system.serviceModel>
  <behaviors>
    <endpointBehaviors>
      <behavior name="ServiceX.RestBehavior">
        <webHttp />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="ServiceX.RestBehavior">
        <serviceMetadata httpGetEnabled="false" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />

  <services>
    <service behaviorConfiguration="ServiceX.RestBehavior"
      name="ServiceX.Rest">
      <endpoint address="" behaviorConfiguration="ServiceX.RestBehavior"
        binding="webHttpBinding" contract="ServiceX.IRest" />
    </service>
  </services>
</system.serviceModel>

All works fine without wildcard mapping; I can browse to '/services/rest.svc/test' and I'll receive the expected result.

However, as soon as I enable wildcard mapping (.* > C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll), then I start receiving 404s when I attempt to access a method (although I can still view '/services/rest.svc').

I've exhausted Google and StackOverflow :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我太投入 2024-10-13 06:56:56

我刚刚在 IIS6 上运行 WCF 服务时遇到了同样的问题。

我可以在 http://someurl/service.svc 上浏览服务,但是当点击服务上的方法,例如 http://someurl/service.svc/somemethod

就我而言,修复很简单。 .svc 文件类型在 IIS 中配置为由 C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 处理,但我的服务在 ASP.NET v4.0 应用程序池中运行,所以我只需指向由 C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll 处理的 .svc 文件类型

I just had the same problem with a WCF service running on IIS6.

I could browse the service on http://someurl/service.svc, but I would get a 404 when hitting a method on the service such as http://someurl/service.svc/somemethod.

The fix, in my case, was easy. The .svc file type was configured in IIS to be handled by C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll, but my service was running in a ASP.NET v4.0 apppool, so I simply pointed the .svc file type to be handled by C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文