如何为WCF服务创建重定向?

发布于 2024-12-26 19:36:07 字数 773 浏览 0 评论 0原文

我的网站 A 上托管了一个 WCF 服务。我还有另一个网站 B,它使用 IIS URL 重写将所有请求重定向到我的网站 A。但是,站点 B 不处理任何对 .svc 文件的请求,返回 404 not find。知道如何让它发挥作用吗?

UPD重定向配置是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect" stopProcessing="true">
                    <match url=".*" />
                    <action type="Rewrite" url="http://localhost/site_A/{R:0}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

我发现网站A的IIS日志中没有任何对.svc文件的请求(!)。它不会将这些请求重定向到站点 A。但是,当我从站点 B 请求 .htm 文件时,它会正确地将它们重定向到站点 A。

I have a WCF service hosted on my website A. And I have another site B, that redirects all requests to my site A using IIS URL rewriting. However, site B doesn't handle any requests to .svc files, returns 404 not found. Any idea how to make it working?

UPD redirection config is like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect" stopProcessing="true">
                    <match url=".*" />
                    <action type="Rewrite" url="http://localhost/site_A/{R:0}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

I've found that there is no any requests to .svc files in the IIS logs of website A (!). It doesn't redirect these requests to site A. However, when I request .htm files from the site B, it redirects them to site A correctly.

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

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

发布评论

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

评论(3

我不确定,但据我记得,如果您在网站 B 上没有 .svc 的 http 处理程序,则可能会发生这种情况

I'm not sure, but as far as I remember it may happen if you don't have http handler for .svc on web site B

疯了 2025-01-02 19:36:07

即使您要在 IIS 中添加 .SVC 处理程序并以与处理 .HTM 请求相同的方式重定向它,重定向也不会保留消息正文。因此,对 SiteB 上的服务方法的请求不一定与 SiteA 上的服务方法调用相同 - 这取决于您的配置、是否以 REST方式公开以及您的绑定是什么。

您可以查看WCF 4.0 的路由功能。这需要您编写某些逻辑来识别调用并让它调用另一个端点。

一个“更简单”的解决方案是简单地让 SiteB 托管一个代理服务,该服务仅接受传入请求并调用 SiteA 的等效服务,获取结果并将其返回给调用者。

Even if you were to add a .SVC handler in IIS and redirect it in the same manner as you do the .HTM requests, the redirection will not preserve the body of the message. So a request to a service method on SiteB will not necessarily be the same as a service method call on SiteA - this depends on your configuration, whether it is exposed RESTfully, and what your bindings are.

You can have a look at WCF 4.0's Routing feature. This requires you to write certain logic to recognize a call and have it call another endpoint.

A 'cruder' solution is to simply have SiteB host a proxy service which simply accepts incoming requests and calls SiteA's equivalent service, gets the result and returns it to the caller.

苍暮颜 2025-01-02 19:36:07

如果您仍然需要服务器处理其他常规流量(包括某些服务),一种选择是创建一个仅用于没有托管代码的重定向的应用程序池。

示例:

 IIS 具有“网站”主站点和 2 个应用程序:“WcfServices”和“其他网站”

假设您希望将所有内容 http://Websites/WcfServices 重定向到其他地方。

首先,确保已安装 URL 重写和 ARR 并设置反向代理。 (请注意,您也可以更改入站重写规则以指向特定路径,而不仅仅是另一台服务器)

重写 URL 设置为的入站重写规则操作http://internalWebServer:8080/internalWcfServices/{R:0}

为无托管代码的 WcfServices 创建应用程序池:

添加应用程序池名称:WcfServiceRedirect;版本:无托管代码

确保 WcfServices 使用新的应用程序池:

WcfServices 应用程序的基本设置页面,应用程序池设置为 WcfServiceRedirect

此时,WCF 无法拦截对某些内容的调用就像 http://Websites/WcfService/CustomerDetails.svc 因为无法加载 .net 模块。所有流量都会路由到反向代理中设置的内部服务器。

If you still need the server to handle other regular traffic including some services, one option is to create an app pool just for redirection that has no managed code.

Example:

IIS With a main site of "Websites" and 2 applications: "WcfServices" and "OtherWebsites"

Say that you want everything to http://Websites/WcfServices to redirect somewhere else.

First, make sure that URL Rewrite and ARR are installed and setup your reverse proxy. (Note that you can change the inbound rewrite rule to point to a specific path as well, not just another server)

Action for Inbound Rewrite Rule with Rewrite URL set to http://internalWebServer:8080/internalWcfServices/{R:0}

Create an app Pool for WcfServices with No Managed Code:

Add Application Pool. Name: WcfServiceRedirect; .NET CLR version: No Managed Code

Make sure that WcfServices uses the new app pool:

WcfServices app's Basic Settings page with Application Pool set to WcfServiceRedirect

At this point, WCF cannot intercept calls to something like http://Websites/WcfService/CustomerDetails.svc since no .net modules can be loaded. All traffic will be routed to the internal server set in the reverse proxy.

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