【问题标题】:.net 4 WCF Routing Service + REST.net 4 WCF 路由服务 + REST
【发布时间】:2010-07-19 13:22:38
【问题描述】:

是否可以将 WCF 4 中的新 WCF 路由服务用于基于 REST 的服务?我想到了类似于反向代理的东西。基本上,我有许多基于自托管的基于休息的服务,我想通过具有相同基本 url 和端口的 IIS 公开这些服务。路由应该由 url 的最后一部分完成。我对 thw WCF 路由服务完全陌生,如果这是一个愚蠢的问题,请原谅我,但我在网上找不到任何相关信息。

我尝试过这样的事情(其中 serivce1/2 是自托管服务):

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="RoutingBehavior">
                <routing routeOnHeadersOnly="false" filterTableName="RoutingTable"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <serviceMetadata httpGetEnabled="true"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="RoutingBehavior" name="System.ServiceModel.Routing.RoutingService">
            <endpoint address="myservices" contract="System.ServiceModel.Routing.IRequestReplyRouter" binding="basicHttpBinding"/>
        </service>
    </services>
    <routing>
        <filterTables>
            <filterTable name="RoutingTable">
                <add filterName="service1Filter" priority="0" endpointName="service1"/>
                <add filterName="service2Filter" priority="0" endpointName="service2"/>
            </filterTable>
        </filterTables>
        <filters>
            <filter name="service1Filter" filterType="MatchAll"/>
            <filter name="service2Filter" filterType="MatchAll"/>
        </filters>
    </routing>
    <client>
        <endpoint address="http://somehost:8888/test/service1" binding="basicHttpBinding" contract="*" name="service1"/>
        <endpoint address="http://somehost:8732/test/service2" binding="basicHttpBinding" contract="*" name="service2"/>
    </client>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>

但这似乎不起作用。我得到一个未找到端点的异常。 http://somehost:8888/test/service1 是自托管服务的基地址,而不是实际端点。我可以根据基地址进行路由吗?或者(如果可以使用其他路由)我必须为每个端点添加路由吗?

【问题讨论】:

  • 我认为这可能会误用 WCF 路由服务。我将使用像 ARR 这样的“真正的”反向代理。

标签: wcf


【解决方案1】:

我通过使用反向代理解决了这个问题(在我的例子中是 arr)。我不知道是否可以为此目的使用 WCF 路由服务,但这可能是一种误用。

【讨论】:

  • 要详细说明这条好建议,我必须安装 ARR 扩展,然后在 iis 中启用代理以允许将 url 重写到其他主机,然后在我的 wcf 路由服务中创建重写规则web.config 以便soap 和直接的html 得到处理有点透明。对于比我的不那么琐碎的 Web 内容,可能需要一些出站规则。
【解决方案2】:

路由服务仅适用于 SOAP 请求。要在 RESTful WCF 中使用路由,您需要使用 System.Web.Routing 设置路由,类似于 MVC 路由。

【讨论】:

    猜你喜欢
    • 2011-07-16
    • 2011-09-11
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 2011-04-15
    • 2020-11-16
    • 2011-05-04
    • 2011-07-05
    相关资源
    最近更新 更多